【问题标题】:URL Masking with htaccess使用 htaccess 进行 URL 掩码
【发布时间】:2013-10-09 13:17:55
【问题描述】:

我在下面有一个网址:

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

我该如何为此编写 htaccess?

【问题讨论】:

    标签: .htaccess url masking


    【解决方案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

    【讨论】:

    • 当我打开我的网站时它不起作用,例如abc.com/…
    • 所以您输入的 URL 为 http://www.mysite.com/mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price=?
    • 是的,它应该更改为该 url 并打开 mypage.php/TimeshareForRent/All/ 但在后面传递变量,实际上用 mypage.php/TimeshareForRent/All/ 屏蔽变量
    • 哦它不再给出错误但是当我打开这个链接时:site.com/… ...它不会改变到另一个网址
    • 不在一个名为 testing 的文件夹中,你能做一些它在文件夹中工作的事情吗?
    【解决方案2】:

    您可以使用此行并在 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 2016-12-25
      • 2014-05-27
      • 2021-05-21
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      相关资源
      最近更新 更多