当前位置: 代码迷 >> PHP >> .htaccess伪静态有关问题
  详细解决方案

.htaccess伪静态有关问题

热度:108   发布时间:2016-04-28 17:30:50.0
.htaccess伪静态问题
.htaccess伪静态问题

RewriteEngine on
Rewritebase /
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

我一直用这个,这个有个缺点是什么文件都给包含进去了

比如你访问whois.hangye5.com/womai.cn
这样是可以的
但是如果访问whois.hangye5.com/sitemaps/sitemap1.html
也会跑到index.php文件里去
我想这二个文件不要都跑index.php里去,要修改哪些
------解决思路----------------------
#当目录存在时不做重写
RewriteCond %{REQUEST_FILENAME} !-d

#当文件存在时不做重写
RewriteCond %{REQUEST_FILENAME} !-f

whois.hangye5.com/sitemaps/sitemap1.html
也会跑到index.php文件里去,显然 sitemaps/sitemap1.html 是不存在的

 ^(.*)$ 把一切不存在的东西都包括进去了,所以 404 设置不会起作用(index.php 总是存在的)
你需要在那个 .* 上做文章
------解决思路----------------------
RewriteRule ^(.*)/sitemaps/sitemap(\d+)\.html$ $1/sitemaps/sitemap.php?domain=$2
  相关解决方案