2010-10-01 54 views
0

我有一些麻煩與我的腳本的.htaccess例外..幾個子文件夾

,當我訪問http://www.domain.com/this-is-a-topic我希望它重定向到http://www.domain.com/index.php?t=this-is-a-topic ...但是當它說:「管理」,「網站地圖」或一些其他的事情,我希望它看起來要麼另一個改寫狀態或只是簡單地讓http://www.domain.com/administration/

這裏是我的代碼:

RewriteCond %{REQUEST_URI} !(administration|sitemap)/(.*)\. [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 


# Dync links 

RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L] 
RewriteRule ^lang:([0-9]+)?$     index.php?l=$1 [L] 


RewriteRule ^sitemap/?$       index.php?sitemap=sitemap [L] 

RewriteRule ^error/([0-9]+)?$     index.php?error=$1 
RewriteRule ^([a-zA-Z0-9-]+)/?$    index.php?t=$1 

的問題是,當我寫/管理/它去http://www.domain.com/index.php?t=/administration/而不是去http://www.domain.com/administration/index.php

回答

0

這裏有兩個問題。首先,你的條件

RewriteCond %{REQUEST_URI} !(administration|sitemap)/(.*)\. [NC] 

將永遠是真實的,因爲%{REQUEST_URI}價值始終擁有領先的正斜槓(這樣的格局將永遠不匹配)。對於直接瀏覽到站點地圖和管理文件夾的情況,您也可能不想查找該點。

其次,條件僅適用於第二天規則,因此當文件夾會爲規則

RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L] 

,他們不會爲

RewriteRule ^([a-zA-Z0-9-]+)/?$     index.php?t=$1 

被忽略被忽略有幾種方法解決這個問題,但最容易的可能是忽略規則的其餘部分,在這種情況下,您的任何條件與前期匹配,如下所示:

# Don't rewrite and stop processing if any of the following is true 
RewriteCond %{REQUEST_URI} ^/(administration|sitemap)/ [NC,OR] 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 

# Dync links 
RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L] 
RewriteRule ^lang:([0-9]+)?$     index.php?l=$1 [L] 

RewriteRule ^sitemap/?$       index.php?sitemap=sitemap [L] 

RewriteRule ^error/([0-9]+)?$     index.php?error=$1 
RewriteRule ^([a-zA-Z0-9-]+)/?$     index.php?t=$1 
+0

它不起作用 - 它仍然重定向到404錯誤頁面:/ – 2010-10-03 20:30:42

+0

或更準確地說 - 它重定向到使用php-headers創建的「error/404 /」!這意味着,如果所需的文件夾/文件不存在,它將重定向到錯誤/ 404/:) – 2010-10-03 20:35:30

+0

@Dennis Lauritzen:嗯......好吧,我會把它放在我的測試服務器上看看可能會出現什麼問題。 – 2010-10-03 20:49:32