We know that apache has several places to implement virtual host configuration, but to implement 301 redirection, we know that there are at least three places to implement, vhosts. conf, httped. conf ,. in the htaccess file, the following describes the configuration method.
Create a. htaccess file // you can use windows cmd or a text editor.
301 the redirection code is as follows:
The Code is as follows: |
Copy code |
RewriteEngine on RewriteCond % {http_host} ^ abc.com [NC] RewriteRule ^ (. *) $ http://www.baidu.com/#1 [R = 301, L] RewriteCond % {http_host} ^ www.abc.com [NC] RewriteRule ^ (. *) $ http://www.baidu.com/#1 [R = 301, L] |
You can define multiple entries to achieve multiple jumps at the same time.
Configure 301 redirection in vhosts. conf in Apache
To achieve URL standardization, SEO usually redirects a domain name without WWW to a domain name with WWW. The configuration in vhosts. conf is as follows:
The Code is as follows: |
Copy code |
<VirtualHost *: 80> ServerName www. Domain Name. com DocumentRoot/home/fari001Com </VirtualHost> <VirtualHost *: 80> ServerName domain name 1.com RedirectMatch permanent ^/(. *) http: // www. Domain Name. com/$1 </VirtualHost> |
In Apache, besides the above two methods, there are other configuration methods and optional parameters.