In this tutorial, I'll cover how to setup an .htaccess configuration file for redirecting to website page. It is simple to use, Hypertext access (.htaccess) is a configuration file automatically executed and detected by the Apache web server.
Just create a .htaccess file in a text editor and upload it to your website’s root directory(public_html) and add the following code.
Example 1<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Example 2RewriteEngine On DirectoryIndex disabled RewriteRule ^$ http://107.180.34.196:8080/ [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ http://107.180.34.196:8080/$1 [P,L]
React js and php
Example 1<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule . /index.html [L] </IfModule>
Example 1<IfModule mod_rewrite.c> Options +FollowSymLinks IndexIgnore */* RewriteEngine On # If its not HTTPS RewriteCond %{HTTPS} off RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !\/$ RewriteRule ^(.*) / </IfModule>
Example 2<IfModule mod_rewrite.c> Options +FollowSymLinks IndexIgnore */* RewriteEngine On # If its not HTTPS RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$ RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)? RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !\/$ RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$ RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)? RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteRule ^(.*) / </IfModule>
Blacklisting by IP
Blacklistingorder allow,deny allow from all deny from 178.137.83.166 deny from 128.137.47.134
Whitelisting by IP
Whitelistingorder deny,allow deny from all allow from 178.137.83.166 allow from 128.137.47.134
Conclusion
In this post, you’ve learned the easy way to setup an .htaccess configuration file for automatically website redirects and block(Blacklisting by IP) or allow(Whitelisting by IP) visitors from specific countries.