Our goal is to put http://www.bulknews.cn/show.php? Id = 1014700 can be directly accessed at http://www.bulknews.cn/1014700.htmlthrough rewrite url rewriting
1. Configure httpd. conf of apache to make the. htaccess file take effect.
ServerAdmin a@ B .com
DocumentRoot/var/www/bulknews
ServerName www.bulknews.cn
Options FollowSymLinks
AllowOverride All
ErrorLog "|/usr/local/sbin/cronolog/var/log/www/wapya/www.bulknews.cn _ error_log. % Y % m % d"
CustomLog "|/usr/local/sbin/cronolog/var/log/www/wapya/www.bulknews.cn _ access_log. % Y % m % d" combined
Note: FollowSymLinks and AllowOverride must be set to All. Otherwise, the rewrite engine does not work at All. If your apache default root directory is/var/www, in the/var/www configuration field, you must also set
Options FollowSymLinks
AllowOverride All
Because of this, I only set it on the virtual host, which makes it impossible to convert static pages.
2. Set the. htaccess file under/var/www/bulknews
The simplest configuration on our side is
RewriteEngine on
RewriteBase/
RewriteRule (. +)/. html $ show. php? Id = $1 [L]
OK, restart the web service, then you can access the http://www.bulknews.cn/1014700.html normally
// ================================================ ================================== //
Forward one domain name to another in httpd
The virtual host world has recently changed its domain name. The new domain name is www.wbhw.com. In this case, you need to direct the original domain name webhosting-world.com, and the address of the Forum webhosting-world.com/forums/ to the new domain name, so that the user can find, and make the original Forum URL continue to be valid without 404 not found, for example, the original http: // www. webhosting-world.com/forums/-f60.html, let it continue to work under the new domain name, click and forward to the http://bbs.wbhw.com/-f60.html, which requires the Mod_rewrite function of apache to achieve.
Add the following redirection rules in <virtualhost>:
RewriteEngine On
# Redirect webhosting-world.com/forums to bbs.wbhw.com
RewriteCond % {REQUEST_URI} ^/forums/
RewriteRule/forums/(. *) http://bbs.wbh?com/#1 [R = permanent, L]
# Redirect webhosting-world.com to wbhw.com
RewriteCond % {REQUEST_URI }! ^/Forums/
RewriteRule/(. *) http://www.wbh?com/#1 [R = permanent, L]
After the above rules are added, all content in the rules is as follows:
<Virtualhost *: 80>
ServerAlias webhosting-world.com
ServerAdmin admin@webhosting-world.com
DocumentRoot/path/to/webhosting-world/root
ServerName www.webhosting-world.com
RewriteEngine On
# Redirect webhosting-world.com/forums to bbs.wbhw.com
RewriteCond % {REQUEST_URI} ^/forums/
RewriteRule/forums/(. *) http://bbs.wbh?com/#1 [R = permanent, L]
# Redirect webhosting-world.com to wbhw.com
RewriteCond % {REQUEST_URI }! ^/Forums/
RewriteRule/(. *) http://www.wbh?com/#1 [R = permanent, L]
</Virtualhost>
Example 1 of URL redirection:
1. http://www.zzz.com/xxx.php-> http://www.zzz.com/xxx/
2. http://yyy.zzz.com> http://www.zzz.com/user.php? Username = yyy
RewriteEngine On
RewriteCond % {HTTP_HOST} ^ www.zzz.com
RewriteCond % {REQUEST_URI }! ^ User/. php $
RewriteCond % {REQUEST_URI}/. php $
RewriteRule (. *)/. php $ http://www.zzz.com/4101/ [R]
RewriteCond % {HTTP_HOST }! ^ Www.zzz.com
RewriteRule ^ (. +) % {HTTP_HOST} [C]
RewriteRule ^ ([^/.] +)/. zzz/. com http://www.zzz.com/user.php? Username = $1
Example 2:
/Type. php? Typeid = * -->/type *. html
/Type. php? Typeid = * & page = * -->/type * page *. html
RewriteRule ^/type(%0-9%%%%%.html $/type. php? Typeid = $1 [PT]
RewriteRule ^/type(%0-9%%%%%%page(%0-9%%%%%%.html $/type. php? Typeid = $1 & page = $2 [PT]
Address: http://blog.csdn.net/phpsome/archive/2009/06/05/4246344.aspx