2014-12-23 45 views
1

我有兩個htaccess文件,其中一個位於根目錄中,另一個位於禮物/目錄中。兩個.htaccess文件不能一起工作

的.htaccess包含:

RewriteEngine on 
RewriteCond %{REQUEST_URI} /gifts/ 
RewriteRule gifts/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)$ gifts/catalog.php?catalog=$1 [NC,L] 

RewriteCond %{REQUEST_URI} /gifts/ 
RewriteRule gifts/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)/([0-9]+)$ gifts/catalog.php?catalog=$1&page=$2 [NC,L] 

禮品/的.htaccess包含:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^gifts.example.com$ [NC] 
RewriteRule ^([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)$ /catalog.php?catalog=$1 [NC,L] 
RewriteCond %{HTTP_HOST} ^gifts.example.com$ [NC] 
RewriteRule ^([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)/([0-9]+)$ /catalog.php?catalog=$1&page=$2 [NC,L] 

當我去到以下網址:

http://gifts.example.com/jeans

它的工作原理,但下面的URL不起作用時

http://example.com/gifts/jeans

Not Found錯誤

回答

1

嘗試gifts/.htaccess爲:

RewriteEngine on 
RewriteBase /gifts/ 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([A-Za-z0-9-]+)/?$ catalog.php?catalog=$1 [QSA,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/?$ catalog.php?catalog=$1&page=$2 [QSA,L] 
+0

對不起,沒不工作 – sAs59

+0

它適用於http ://example.com/gifts/jeans now,but not for http://gifts.example.com/jeans – sAs59

+0

此規則與'gifts.example.com/jeans'無關,因爲它位於'/ gifts /'目錄 – anubhava