记录一下Apache Rewrite成功配制的几个关键点

1. LoadModule rewrite_module modules/mod_rewrite.so

2.  AllowOverride None 改成  AllowOverride All

3.  在<VirtualHost>中定义rewrite规则

4. 改完以后service httpd restart

完整的配制如下:

<VirtualHost *:80>
ServerName www.x.com
DocumentRoot “/var/www/html/test”
<Directory “/var/www/html/test/”>
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.php index.html index.shtml
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
RewriteLog /etc/httpd/conf/rewrite.log
RewriteLogLevel 3
<IfModule rewrite_module>
RewriteEngine On
RewriteRule ^/book_([0-9]+)\.html$ /book.php?BookID=$1
RewriteRule ^/zhang_([0-9]+)\.html$ /zhang.php?BookID=$1 [L]
RewriteRule ^/down_([0-9]+)\.html$ /down.php?BookID=$1 [L]
RewriteRule ^/zhang_([0-9]+)_([0-9]+)\.html$ /zhang.php?BookID=$1&SiteID=$2 [L]
RewriteRule ^/read_([0-9]+)_([0-9]+)_([0-9]+)\.html$ /read.php?BookID=$1&ZhangID=$2&SiteID=$3 [L]
RewriteRule ^/News.aspx$ /new.php [L]
RewriteRule ^/Favorite.aspx$ /favorite.php [L]
RewriteRule ^/List.aspx$ /list.php [L]
RewriteRule ^/Top.aspx$ /top.php?Flag= [L]
RewriteRule ^/Login.aspx$ /login.php [L]
RewriteRule ^/Reg.aspx$ /reg.php [L]
RewriteRule ^/Down.aspx$ /down.php?query_string [L]
RewriteRule ^/About.aspx$ /book.php?$query_string [L]
RewriteRule ^/Show.aspx /zhang.php?$query_string [L]
RewriteRule ^/List.aspx?Flag=([a-zA-z]+)&SortID=([0-9]+)$ /list.php?Flag=$1&SortID=$2 [L]
RewriteRule ^/Read.aspx?BookID=([0-9]+)&ZhangID=([0-9]+)&SiteID=([0-9]+)$ /read.php?BookID=$1&ZhangID=$2&SiteID=$3 [L]
</IfModule>
</VirtualHost>

posted @ 2016-12-25 18:37  371502685  阅读(91)  评论(0编辑  收藏  举报