The procedure is as follows:
1. Enable the Rewrite Environment
Edit the/etx/httpd/conf/http. conf file
Remove the # Above "# loadmodule rewrite_module modules/mod_rewrite.so #
2. You also need to authorize ". htaccess" in any directory and change "AllowOverride" to "All"
3. Enable RewriteEngine and set the value to "On". If there is no RewriteEngine, add a "RewriteEngine On"
4. You can set the default homepage of your site at this time.
Find <DIRECTORY> </DIRECTORY> and add the following content to the two labels:
# Enable php support
AddType application/x-http-php.php
When setting the homepage, I set index.htm and index. php here. Of course you can change it to another one, which is the red part.
DirectoryIndex index.htm
DirectoryIndex index. php
5. now enable URL redirection
I will use an example to illustrate that you can replace the red part with what you need.
URL forwarding
Find "RewriteEngine On"
Add
RewriteCond % {HTTP_HOST} ^ test.www.baidu.com [NC]
<# [NC] indicates the end. The above is the source address you want to forward.
RewriteRule ^ (. *) http://www.centoscn.com/test/test/#r,l]
# The last one is the destination address you forwarded. R indicates that the target address is displayed normally. If it is set to P, the target address is hidden.
6. Now you access ^ test.www.baidu.com will automatically jump to the http://www.centoscn.com/test/test/