1
我需要一些mod_rewrite规则,我尝试使用一些帮助。我需要做两件事情mod_rewrite - 友好的URL和删除页面扩展
变化的动态URL,这样它的友好(例如,
/content.php?CategoryID=1
变化/categories/1/
)在我的网页中删除
.php
扩展(如/page2.php
至/page2
)
好吧,我可以在我的.htaccess文件中使用以下代码自行工作:
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteOptions Inherit
RewriteBase/
RewriteRule ^category/([0-9]+)?$ category/$1/ [R]
RewriteRule ^category/([0-9]+)/?$ content.php?CategoryID=$1
我然后尝试2号,我遇到了几个问题。我使用了以下内容:
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.php$ /%1 [NC,R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(/.+)\.php$
RewriteRule ^(.+)\.php$ %1/ [R=301,L]
RewriteCond %{REQUEST_URI} ^(/.+)/$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule ^.+/$ %1.php [QSA,L]
以上rerwrites的URL,所以它看起来友好(如/page2/
),但它击中我的404页,在这里我重写URL仍然有效,我无法查看,但我的其他网页(例如/category/1/
)。
这是我的全部.htaccess文件:
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteOptions Inherit
RewriteBase/
RewriteRule ^category/([0-9]+)?$ category/$1/ [R]
RewriteRule ^category/([0-9]+)/?$ content.php?CategoryID=$1
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.php$ /%1 [NC,R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(/.+)\.php$
RewriteRule ^(.+)\.php$ %1/ [R=301,L]
RewriteCond %{REQUEST_URI} ^(/.+)/$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule ^.+/$ %1.php [QSA,L]
ErrorDocument 404 /misc/404page.html
任何帮助,因为我是新来的这一切的mod_rewrite和正则表达式的东西将不胜感激。
尝试使用mod_rewrite的日志记录(请参阅['RewriteLogLevel'](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel))。 – Gumbo 2010-09-04 12:15:23