删除.php扩展名mod_rewrite有效,但标记页面不起作用


Removing .php extension with mod_rewrite works but tags pages does not

我有这样的.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.*

更新:好的,再次阅读您的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

解决方案是在末尾添加:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^'.]+)$ $1.php [NC,L]