我的 htaccess 文件中有这条重写规则,删除了 URL 上的 index.php 以仅显示域名
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
但它似乎显示 404 not found on all other directories。例如,我有一个名为 admin 的目录,如果我转到 www.domain.com/admin,我会收到 404 not found
我在 RewriteCond 代码上面也有这段代码
RewriteCond %{REQUEST_URI} !^/admin [NC]
这是我的完整 htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteCond %{REQUEST_URI} !^/status [NC]
RewriteCond %{REQUEST_URI} !^/customer [NC]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
# Rewrites /services to be /home.php?id=services
RewriteRule ^([a-zA-Z0-9-]+)/?$ /home.php?id=$1 [L,QSA]
#BLOG
# Rewrites /blog/this-is-a-blog-post to be /home.php?id=blog&slug=this-is-a-blog-post
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /home.php?id=$1&slug=$2 [L,QSA]
# Rewrites /blog/year2013/month12 to be /home.php?id=blog&year=2013&month=01
RewriteRule ^([a-zA-Z0-9-]+)/year([0-9]+)/month([0-9]+)/?$ /home.php?id=$1&year=$2&month=$3 [L,QSA]
最佳答案
我相信服务规则在这里引起了问题。将其更改为:
# Rewrites /services to be /home.php?id=services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ /home.php?id=$1 [L,QSA]
对博客规则也做同样的事情:
#BLOG
# Rewrites /blog/this-is-a-blog-post to be /home.php?id=blog&slug=this-is-a-blog-post
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /home.php?id=$1&slug=$2 [L,QSA]
关于regex - Htaccess 重写显示 404 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20729553/