Htaccess Rewrite显示404未找到

时间:2013-12-22 12:44:39

标签: regex apache .htaccess mod-rewrite

我的htaccess文件中有这个重写规则,删除URL上的index.php只显示域名

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

但它似乎显示在所有其他目录中找不到404。例如,我有一个名为admin的目录,如果我访问www.domain.com/admin,我找不到404

我在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]

1 个答案:

答案 0 :(得分:0)

我认为服务规则在这里引起了问题。将其更改为:

# 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]