简体   繁体   English

htaccess 2的URL屏蔽

[英]URL Masking with htaccess 2

I have the following url: 我有以下网址:

http://site/testing/mypage.php?PropertyBuyRent=sell&Developer=&Resort=&City=&State=&Country=US&Price=

I have htaccess that checks that if there is something in the variable country, it changes the url like this: 我有htaccess来检查是否在可变国家/地区有东西,它会像这样更改网址:

http://site/testing/mypage.php/TimeshareForSale/US

My htaccess file is below: 我的htaccess文件如下:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(testing/mypage\.php)\?PropertyBuyRent=sell&Developer=&Resort=&City=&State=&Country=([^&]+)&Price= [NC]

RewriteRule ^ /%1/TimeshareForSale/%2? [R=301,L,NE]

RewriteRule ^(testing/mypage.php)/TimeshareForSale/([^/]+)/?$ /$1?PropertyBuyRent=sell&Developer=&Resort=&City=&State=&Country=$2&Price= [L,NC,QSA]

which works perfectly fine.. and redirects me to the above url i stated, but in my php file my variable no longer works which is $_GET['Country'] if i remove the htaccess it prints it fine. 这工作得很好..并将我重定向到我说的上述URL,但是在我的php文件中,如果我删除了htaccess,我的变量将不再有效,它是$ _GET ['Country'],它可以正常打印。

"I have the following url:" “我有以下网址:”

"It changes the url like this:" “它会像这样更改网址:”

Whoa, whoa, whoa! 哇,哇,哇! You may be falling into the common trap of writing the .htaccess backwards. 您可能陷入了向后编写.htaccess的常见陷阱。

http://site/testing/mypage.php/TimeshareForSale/US

is the "search engine friendly" external version of the URL. 是网址的“搜索引擎友好” 外部版本。 It will not work with your PHP code without first being converted (in .htaccess) to 如果不首先将其转换为.htaccess文件,则它无法与您的PHP代码一起使用

http://site/testing/mypage.php?PropertyBuyRent=sell&Developer=&Resort=&City=&State=&Country=US&Price=

While this will work with or without an .htaccess URL rewrite, I presume you're trying to shield your users from it. 尽管无论是否重写.htaccess URL都可以使用,但我认为您正在尝试使用户免受此威胁。 .htaccess is for converting the first form into the second (inbound), not the other way around (outbound). .htaccess是用于将第一种形式转换为第二种形式(入站),而不是用于其他形式(出站)。

Now, in which direction are you trying to go? 现在,您要朝哪个方向前进?

就像您拥有它一样,它可以正常工作,您只需要更改所有类型的链接,因为您不能在所有条件下都使用分时度假/我们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM