使用htaccess进行URL屏蔽

时间:2013-10-09 13:17:56

标签: .htaccess url masking

我的网址如下:

http://www.mysite.com/mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price=

  1. 如果PropertyBuyRent = rent且所有其他变量都为空,那么url应该是这样的: http://www.mysite.com/mypage.php/TimeshareForRent/All
  2. 我怎么能为此写htaccess?

2 个答案:

答案 0 :(得分:1)

您可以使用此规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(testing/mypage\.php)\?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [NC]
RewriteRule ^ /%1/TimeshareForRent/All? [R=301,L]

RewriteRule ^(testing/mypage.php)/TimeshareForRent/All/?$ /$1?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [L,NC,QSA]

参考:Apache mod_rewrite Introduction

答案 1 :(得分:0)

您可以使用此行并在php文件中进行编辑,如下所示

RewriteRule ^mypage.php/TimeshareForRent/All/?$ mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [L,NC,QSA]

当条件匹配时,您可以告诉您的php文件重定向到“mypage.php / TimeshareForRent / All”,因为根据上述规则,它将使用没有变量的变量屏蔽变量的URL