使用mod_rewrite删除.php扩展名有效但标记页面不能

时间:2012-07-01 17:18:19

标签: php .htaccess mod-rewrite tags

我有这样的.htaccess文件:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule (.*)/sites/([^a-zA-Z][0-9_/]*$) $1.php?sites=$2 [L]
RewriteRule (.*)/sites/([0-9_/]*)/(.*) $3 [L]
RewriteRule (.*)/sites/(.*) $2 [L]
RewriteRule tags_xml/(.*).xml tags/display_xml.php?tag=$1 [L]
RewriteRule news_xml/(.*).xml rss.php?site=$1 [L]
RewriteRule tags/([ÄĂ“ĹŚĄŻŹĆĹęółśążźćńa-zA-Z0-9%\ ]*)/([^a-zA-Z][0-9_/]*$) tags/display.php?tag=$1&page=$2 [L]
RewriteRule tags/([ÄĂ“ĹŚĄŻŹĆĹęółśążźćńa-zA-Z0-9%\ ]+) tags/display.php?tag=$1 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2&kom_page=$3 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*) $4 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*) $3 [L]
RewriteCond %{THE_REQUEST} ^.*index.php.*

现在我进入

  

www.domain.com/file

而不是

  

www.domain.com/file.php

它运作正常,但是当我进入

  

www.domain.com/tags/Bank

我没有找到这样的标签错误。此文件夹中的其他脚本也只显示“未找到此类标记”。

之前的工作代码是:

RewriteEngine On
RewriteBase /
RewriteRule (.*)/sites/([^a-zA-Z][0-9_/]*$) $1.php?sites=$2 [L]
RewriteRule (.*)/sites/([0-9_/]*)/(.*) $3 [L]
RewriteRule (.*)/sites/(.*) $2 [L]
RewriteRule tags_xml/(.*).xml tags/display_xml.php?tag=$1 [L]
RewriteRule news_xml/(.*).xml rss.php?site=$1 [L]
RewriteRule tags/([ĘÓŁŚĄŻŹĆŃęółśążźćńa-zA-Z0-9%\ ]*)/([^a-zA-Z][0-9_/]*$) tags/display.php?tag=$1&page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule tags/([ĘÓŁŚĄŻŹĆŃęółśążźćńa-zA-Z0-9%\ ]+) tags/display.php?tag=$1 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2&kom_page=$3 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*) $4 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*) $3 [L]
RewriteCond %{THE_REQUEST} ^.*index.php.*

2 个答案:

答案 0 :(得分:0)

更新: 好的,再次阅读你的htaccess之后,我注意到你使用了以下内容:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

在某些系统上,这将指向您的文件系统,因此添加DOCUMENT_ROOT可能对您有用。像这样:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

答案 1 :(得分:0)

解决方案是在最后添加:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
相关问题