2012-07-01 60 views
1

我有這樣的.htaccess文件:與mod_rewrite的作品,但標籤頁面中刪除擴展名爲.php不

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.* 
+1

「以前的工作代碼」 - 如果它的工作原理,爲什麼不利用呢? – JJJ

+0

它適用於標籤,但不適用於從文件中移除.php。 – Spacedust

+0

這個問題是否需要你所有的代碼?你可以去掉不必要的行嗎? – HerrSerker

回答

0

解決的辦法是隻在結尾處加上:

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

但我仍然猜測我的answare爲您提供瞭解決問題所需的幫助? –

+0

不,我只是在錯誤的地方粘貼代碼;) – Spacedust

+0

啊!我明白了,很好,你找到了解決方案:-) –

0

更新: OK,通過你的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 
+0

這只是翻譯錯誤。它正確完成,它不工作。 – Spacedust

+0

你的線條的tagi /顯示部分? –

+0

我需要從波蘭語翻譯它。 – Spacedust