2012-07-16 93 views
0

我使用htaccess傳遞2個變量。主題&品牌從htaccess中識別變量

RewriteRule ^([A-Za-z0-9_-]+)/?$ ?subject=$1 [NC,L] 
RewriteRule ^([A-Za-z0-9_-]+)/?$ ?brand=$1 [NC,L] 

在我的函數文件我使用頁面檢測,包括各自的模塊。

if (!empty($_REQUEST['subject'])) 
{ 
    include_once("templates/pages.php"); 

} 

else if (!empty($_REQUEST['brand'])) 
{ 
    include_once("templates/brands_content.php"); 

} 

問題: 我無法檢測到的變量....它總是加載「模板/ pages.php」 任何人都可以引導我解決這個問題吧。

感謝

回答

0

第二條規則,RewriteRule ^([A-Za-z0-9_-]+)/?$ ?brand=$1 [NC,L]永遠不會匹配,因爲任何請求URL匹配的第一個(爲主題)。主題或品牌的URL顯示方式顯然沒有區別。

http://yourdomain.com/12345 

「12345」是一個品牌還是標的?您或者需要使正則表達式匹配主題和品牌互斥(或者,如果不是主題,第一條規則總是首先匹配),或者您可以通過將URI添加到品牌或主題來明確說出什麼是品牌或主題:

http://yourdomain.com/subject/12345 
http://yourdomain.com/brand/12345 

就這樣您的規則將是:

RewriteRule ^subject/([A-Za-z0-9_-]+)/?$ ?subject=$1 [NC,L] 
RewriteRule ^brand/([A-Za-z0-9_-]+)/?$ ?brand=$1 [NC,L]