两个.htaccess文件无法一起使用

时间:2014-12-23 11:50:44

标签: .htaccess mod-rewrite

我有两个htaccess文件,其中一个位于根目录,另一个位于 gifts / 目录中。

Root .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

可行,但以下网址不起作用

  

http://example.com/gifts/jeans

发现

未找到错误

1 个答案:

答案 0 :(得分: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]