Apache configuration domain Jump
Domain Name jump
It is to realize the jump and hide the real URL address, based on regular expressions Perl language specification. Usually help us achieve quasi-static, quasi directory, domain jump, and so prevent hotlinking.
Parameter format
parameter: Apache mod_rewrite rules rewrite . 1 ) R & lt [= code] (the redirect Force) force an external redirect Description: In an alternative force string with HTTP: // thishost [: thisport] / redirect prefix code to the outside if the URL is not specified, the default will be a 302 HTTP status code. 2 ) F (Force to the URL of Forbidden BE) to disable URL, return 403HTTP status code. . 3 ) G (URL to BE Gone Force) force URL GONE, 410HTTP return status code. . 4 ) P (Proxy Force) enforce forwarding agent. 5 ) L ( Last rule) that the current rule is the last rule, stop the analysis after the rewrite rules. . 6 ) N (Next round) resumes operation from the first rule rewriting process. . 7 ) C (with chained Next rule) associated with the next rule . 8 ) T = MIME- type (MIME type Force) forced MIME type . 9 ) the NS (Used only IF NO Internal Sub- Request) not only for the internal sub-requests 10 ) the NC (NO Case ) is case-insensitive . 11 ) QSA (Query String the append) addition request string 12 is ) NE (NO escaping the URI of Output) is not output escape special characters Description: the RewriteRule /foo/(.*) / Arg bar Pl =% 3D $? . 1 [R & lt, NE] will be able to correct / foo / zoo converted / bar Pl = Arg =? Zoo 13 is ) the PT (Pass through to Next Handler) passed to the next processing Description: RewriteRule (. *) ^ / Abc / def $ 1 [PT] # will be handed over to / def rules dealing Alias / def / ghi 14 ) S = num (Skip Next rule (S)) to skip num rule 15 ) E = on VAR: VAL (Environment variable SET) set environment variables 16 ) representative or OR Note: If the rule matches the normal processing, 8 invalid) after a sign, if you do not match, then the following rules are all associated skipped.
format: # Call mod_rewrite.c module <IfModule mod_rewrite.c> # Open rewirte function RewriteEngine on Host # statement Client request prefixes are not www.client.cn RewriteCond %(HTTP_HOST) ^www.client.com$ If the host is a prefix meaning # Client request meets the above conditions, the direct jump. AuthType Basic ^(.*)$ http://www.server.com/$1 [R=301,L] </IfModule>
Examples of configuration
1, to find out whether there rewrite module, domain jump module
命令:apache2/bin/apachectl -M | grep rewrit rewrite_module (shared) If does not exist: <br> # Edit the main configuration file and extract comments vim httpd.conf<br> LoadModule rewrite_module modules/mod_rewrite.so Note: Without this module, you need to install the module via apxs tool.
2, modify the virtual host configuration file
vim httpd-vhosts.conf # 1 on 1 domain Jump <VirtualHost *:80> DocumentRoot "/usr/local/html" ServerName www.server.com ServerAlias www.aaa.com <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.aaa.com$ RewriteRule ^/(.*)$ http://www.server.com/$1 [R=301,L] </IfModule> <Directory /usr/local/html> require all granted </Directory> </VirtualHost> # 1 multi-domain Jump <VirtualHost *:80> DocumentRoot "/usr/local/html" ServerName www.server.com ServerAlias www.aaa.com ServerAlias www.bbb.com <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR] RewriteCond %{HTTP_HOST} ^www.bbb.com$ RewriteRule ^/(.*)$ http://www.server.com/$1 [R=301,L] </IfModule> <Directory /usr/local/html> require all granted </Directory> </VirtualHost> Profiles
Note: Status Code jump 301 representatives of permanent redirect 302 temporary redirect Note: $ 1 represents the network address followed by the file. NOTE: Visit a " / " can enter the following format. RewriteCond %(HTTP_HOST) 456.com RewriteRule /(.*)$ HTTP://123.com/$1 [R=301,L]
3, re-reads the configuration file
apache2/bin/apachectl graceful
Domain Name jump
It is to realize the jump and hide the real URL address, based on regular expressions Perl language specification. Usually help us achieve quasi-static, quasi directory, domain jump, and so prevent hotlinking.
Parameter format
parameter: Apache mod_rewrite rules rewrite . 1 ) R & lt [= code] (the redirect Force) force an external redirect Description: In an alternative force string with HTTP: // thishost [: thisport] / redirect prefix code to the outside if the URL is not specified, the default will be a 302 HTTP status code. 2 ) F (Force to the URL of Forbidden BE) to disable URL, return 403HTTP status code. . 3 ) G (URL to BE Gone Force) force URL GONE, 410HTTP return status code. . 4 ) P (Proxy Force) enforce forwarding agent. 5 ) L ( Last rule) that the current rule is the last rule, stop the analysis after the rewrite rules. . 6 ) N (Next round) resumes operation from the first rule rewriting process. . 7 ) C (with chained Next rule) associated with the next rule . 8 ) T = MIME- type (MIME type Force) forced MIME type . 9 ) the NS (Used only IF NO Internal Sub- Request) not only for the internal sub-requests 10 ) the NC (NO Case ) is case-insensitive . 11 ) QSA (Query String the append) addition request string 12 is ) NE (NO escaping the URI of Output) is not output escape special characters Description: the RewriteRule /foo/(.*) / Arg bar Pl =% 3D $? . 1 [R & lt, NE] will be able to correct / foo / zoo converted / bar Pl = Arg =? Zoo 13 is ) the PT (Pass through to Next Handler) passed to the next processing Description: RewriteRule (. *) ^ / Abc / def $ 1 [PT] # will be handed over to / def rules dealing Alias / def / ghi 14 ) S = num (Skip Next rule (S)) to skip num rule 15 ) E = on VAR: VAL (Environment variable SET) set environment variables 16 ) representative or OR Note: If the rule matches the normal processing, 8 invalid) after a sign, if you do not match, then the following rules are all associated skipped.
format: # Call mod_rewrite.c module <IfModule mod_rewrite.c> # Open rewirte function RewriteEngine on Host # statement Client request prefixes are not www.client.cn RewriteCond %(HTTP_HOST) ^www.client.com$ If the host is a prefix meaning # Client request meets the above conditions, the direct jump. AuthType Basic ^(.*)$ http://www.server.com/$1 [R=301,L] </IfModule>
Examples of configuration
1, to find out whether there rewrite module, domain jump module
命令:apache2/bin/apachectl -M | grep rewrit rewrite_module (shared) If does not exist: <br> # Edit the main configuration file and extract comments vim httpd.conf<br> LoadModule rewrite_module modules/mod_rewrite.so Note: Without this module, you need to install the module via apxs tool.
2, modify the virtual host configuration file
vim httpd-vhosts.conf # 1 on 1 domain Jump <VirtualHost *:80> DocumentRoot "/usr/local/html" ServerName www.server.com ServerAlias www.aaa.com <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.aaa.com$ RewriteRule ^/(.*)$ http://www.server.com/$1 [R=301,L] </IfModule> <Directory /usr/local/html> require all granted </Directory> </VirtualHost> # 1 multi-domain Jump <VirtualHost *:80> DocumentRoot "/usr/local/html" ServerName www.server.com ServerAlias www.aaa.com ServerAlias www.bbb.com <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR] RewriteCond %{HTTP_HOST} ^www.bbb.com$ RewriteRule ^/(.*)$ http://www.server.com/$1 [R=301,L] </IfModule> <Directory /usr/local/html> require all granted </Directory> </VirtualHost> Profiles
Note: Status Code jump 301 representatives of permanent redirect 302 temporary redirect Note: $ 1 represents the network address followed by the file. NOTE: Visit a " / " can enter the following format. RewriteCond %(HTTP_HOST) 456.com RewriteRule /(.*)$ HTTP://123.com/$1 [R=301,L]
3, re-reads the configuration file
apache2/bin/apachectl graceful