Apache's Pseudo static Rule. htaccess Implementation of 301 Jump Method

informal essay four thousand four hundred and twenty-five 4 years ago (2020-10-18)

First, let's look at the pseudo static rules of the following. htaccess file, which is used to automatically jump to the www domain name when accessing the domain name without www.

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / Order Deny,Allow Deny from 47.114.182.24 RewriteCond %{HTTP_HOST} ^toyean.com [NC] RewriteRule ^(.*)$  https://www.toyean.com/ $1 [L,R=301] RewriteCond %{SERVER_PORT} !^ 443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !- f RewriteCond %{REQUEST_FILENAME} !- d RewriteRule .  /index.php [L] </IfModule>

The "Order Deny, Allow Order from IP Address" rule will prohibit the specified IP from accessing the website, and the set IP access website will display:

Forbidden

You don't have permission to access / on this server.


If you want to prohibit multiple IPs, add several lines "Deny from IP address";

You do not need to disable an IP address. You can manually remove the two lines "Order Deny, Allow Order from IP address".

Summary of the external part:

Domain names without www automatically jump to www domain names:

 RewriteEngine On RewriteCond %{HTTP_HOST} ^toyean.com [NC] RewriteRule ^(.*)$  https://www.toyean.com/ $1 [L,R=301]

The domain name with www automatically jumps to the domain name without www:

 RewriteEngine On RewriteCond %{HTTP_HOST} ^www.toyean.com [NC] RewriteRule ^(.*)$  https://toyean.com/ $1 [L,R=301]

Automatically jump to another domain name:

 RewriteEngine On RewriteCond %{HTTP_HOST} ^www.toyean.com [NC] RewriteRule ^(.*)$  https://www.wulongmao.com/ $1 [L,R=301]