.htaccess使用一个和两个查询字符串变量重写URL

时间:2011-11-20 00:03:53

标签: php apache .htaccess url-rewriting

我正在尝试第一次重写URL,我有以下需要重写的URL:

http://domain.com/resorts.php?countryname=Portugal
http://domain.com/rss.php?destination=Torremolinos&itemtype=rfamily

我在.htaccess文件中写了以下内容:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /countryname/(.*)/ resorts.php?countryname=$1
RewriteRule /destination/(.*)/itemtype/(.*)/ rss.php?destination=$1&itemtype=$2

但是当我尝试以下操作时,我一直在找不到URL。请有人指出我可能做错了什么?非常感谢提前。

http://domain.com/countryname/Portugal
http://domain.com/destination/Torremolinos/itemtype/rfamily

1 个答案:

答案 0 :(得分:3)

您可以使用:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule countryname/(.*)/? resorts.php?countryname=$1 [NC,L]
RewriteRule destination/(.*)/itemtype/(.*)/? rss.php?destination=$1&itemtype=$2 [NC,L]