【发布时间】:2013-12-24 23:03:11
【问题描述】:
我的 htaccess 文件中有这些 mod 重写规则:
RewriteEngine On
# Displays directory if there is no / on the end of the URL
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteCond %{REQUEST_URI} !^/status [NC]
RewriteCond %{REQUEST_URI} !^/customer [NC]
# Removes index.php from URL
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
# Rewrites /services to be /index.php?id=services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?id=$1 [L,QSA]
# Rewrites /blog/this-is-a-blog-post to be /index.php?id=blog&slug=this-is-a-blog-post
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /index.php?id=$1&slug=$2 [L,QSA]
# Rewrites /blog/year2013/month12 to be /index.php?id=blog&year=2013&month=01
RewriteRule ^([a-zA-Z0-9-]+)/year([0-9]+)/month([0-9]+)/?$ /index.php?id=$1&year=$2&month=$3 [L,QSA]
# Rewrites /status/123 to be /index.php?id=status&seq=123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /index.php?id=$1&seq=$2 [L,QSA]
# Rewrites /status/cat1 to be /index.php?id=status&cat=1
RewriteRule ^([a-zA-Z0-9-]+)/cat([0-9]+)?$ /index.php?id=$1&cat=$2 [L,QSA]
/blog 工作正常,但 /status 不行。它显示即使没有目录的目录索引
我基本上想要:
-
home.php?id=services to look like domain.com/services(此为 多个链接/网址)- 工作正常 -
home.php?id=blog&year=2013&month=12看起来像domain.com/blog/year2013/month12工作正常 -
home.php?id=blog&slug=this-is-a-blog-post看起来像domain.com/blog/this-is-a-blog-post工作正常 -
home.php?id=status&cat=123变为domain.com/status/cat123不工作 -
home.php?id=blog&seq=456变为domain.com/status/456不工作
正如您在上面看到的,只有数字 4 和 5 不起作用,它们只是显示未找到的索引或 404 页面,但是 Web 服务器上没有存储名称为 status 的目录em>
我怎样才能修复上面的代码以使它像上面的列表一样工作?
【问题讨论】:
标签: php regex .htaccess mod-rewrite