2012-07-24 60 views
0

我读过几十篇关于类似问题的文章,但是我找不到这篇文章。htaccess mod_rewrite和目录的问题

我有搜索引擎友好的URL在我的网站看起来像这样...

http://www.website.com/tequila/bottle-name.html 
http://www.website.com/whiskey/bottle-name.html 
http://www.website.com/vodka/bottle-name.html 

...其中一瓶-name是瓶子的实际名称。

我正在做一个mod_rewrite到PHP处理程序来实际提供页面。每个处理程序都位于每个目录(龙舌兰酒,伏特加,威士忌)中。

第一个(龙舌兰酒)正在工作,但其他两个都没有,我不知道为什么。

这里是mod_rewrite的代码,我现在所拥有的......

#Rewrite seo urls 
RewriteCond %{REQUEST_URI} !^/tequila/ 
#RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)\.html$ index.php?liquor=$1&liquor-type=tequila [L] 

RewriteCond %{REQUEST_URI} !^/whiskey/ 
#RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)\.html$ index.php?liquor=$1&liquor-type=whiskey [L] 

RewriteCond %{REQUEST_URI} !^/vodka/ 
#RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)\.html$ index.php?liquor=$1&liquor-type=vodka [L] 

这似乎是发生的是威士忌和伏特加页事情败露,由龙舌兰酒mod_rewrite的(猜测处理,因为它是第一个在这里的清单)。因此,http://www.website.com/vodka/vodka-bottle.html实际上被重写为http://www.website.com/tequila/index.php?liquor=vodka-bottle.html&liquor-type=tequila

看来我还没有正确设置RewriteCond%{REQUEST_URI}!^/tequila /?

任何人都可以提供的帮助或指针非常感谢!

+0

我可能错过了一些......你为什么否定'^/tequila /'?这个'!'会引起所有其他**酒类型的匹配,而不是你列出的。 – 2012-07-24 12:26:32

+0

啊......这样做!问题是我对所有这些都没有经验,并且从别人的解决方案中复制/粘贴代码。如果您可以将该评论/解决方案置于答案中,我会将其标记为可接受的解决方案。非常感谢您的帮助! – Rmilligan2372 2012-07-24 12:34:50

+0

添加为答案。此外,不客气:) - 我主要是通过拉开其他代码来自学,所以我感到你的沮丧。 – 2012-07-24 12:44:25

回答

1

你为什么否定^/tequila/?!将导致所有其他酒类的匹配,而不是你列出的。

+0

完美 - 非常感谢! – Rmilligan2372 2012-07-24 12:49:26