2015-03-03 54 views
0

我难住这个htaccess的写规则。htaccess重写问题添加目录

我现在有这个规则运作:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /item\.php\?pid=([a-z0-9]+)\ HTTP/ [NC] 
RewriteRule ^item\.php$ http://www.example.com/%1? [R=301,L] 

RewriteRule ^([-a-z0-9]+)$ /item.php?pid=$1 [NC,L] 

原始地址:

http://www.example.com/item.php?pid=2015-hyundai-genesis-coupe 

启用此网址:

http://www.example.com/2015-hyundai-genesis-coupe 

什么我需要是这样的网址:

http://www.example.com/item/2015-hyundai-genesis-coupe 

我尝试了一堆没有成功的东西。任何人都熟悉这个?

谢谢!

回答

0

你的htaccess更改为这个:

Options -Multiviews 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /item\.php\?pid=([a-z0-9]+)\ HTTP/ [NC] 
RewriteRule ^item\.php$ http://www.example.com/item/%1? [R=301,L] 

RewriteRule ^item/([-a-z0-9]+)$ /item.php?pid=$1 [NC,L] 

您可能会或可能不会需要Options线。这是为了确保在mod_rewrite可以重写请求之前,mod_negotiation不会取代mod-rewrite并将/item映射到/item.php

此外,您可能需要确保在item.php页面中有绝对链接,否则它们将无法正常工作,因为您正在通过将其作为/item/而不是/来更改相对URI库。您也可以将其添加到页面的标题:

<base href="/" /> 
+0

感谢乔恩....我得到它的工作! – aerosport 2015-03-03 05:43:05