我提出了以下重写规则,将php文件作为目录进行处理:
www.domain.com/name.php -> www.domain.com/name/
www.domain.com/name -> www.domain.com/name/
www.domain.com/name/ -> www.domain.com/name.php上面的东西是有效的,但是当标题中有连字符(-)时,它不会在结尾添加尾部斜杠,它将以404页结束。不起作用的例子:
www.domain.com/stack-overflow -> 404 page
www.domain.com/stack-overflow/ -> 404 page当前重写代码:
# 404 page
ErrorDocument 404 /404.php
# Add automatic a trailer slash on the end
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !#
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
# Decline direct access to .php files, redirect .php to name/
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(\w+)\.php$ $1/ [R=301]
# name/ to the right .php file
RewriteRule ^(\w+)/?$ /$1.php有没有人有办法处理标题中有连字符(-)的问题?
提前谢谢。致以亲切的问候,M
发布于 2012-11-09 17:05:14
只需替换以下内容:
\w..。有了这个:
[\w-]Apache的mod_rewrite基本上遵循Perl regexp语法。
https://stackoverflow.com/questions/13304040
复制相似问题