使用htaccess屏蔽URL(带参数)

时间:2012-05-26 15:23:31

标签: .htaccess mod-rewrite url-masking

我需要用一个带有htaccess的相对简单的URL来掩盖长的,愚蠢的php URL。 例如,我需要屏蔽 -

http://mysite.com/index.php?this=that&this=that&whatevs=this&that=&id=5

使用这个简单的网址 -

http://mysite.com/mypage.php

我知道php可以通过获取该页面的内容并显示它来轻松完成这些工作。但在我的条件下,ajax调用和其他一些问题存在一些问题。

此外,我更喜欢使用htaccess。我做了一些研究,但是htaccess代码对我来说非常混乱。

2 个答案:

答案 0 :(得分:1)

所以你只想将http://mysite.com/index.php?this=that&this=that&whatevs=this&that=&id=5重定向到http://mysite.com/mypage.php

然后使用此RewriteRule:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} this=that&this=that&whatevs=this&that=&id=5
RewriteRule ^index.php$ http://mysite.com/mypage.php? [L,R=301]

答案 1 :(得分:1)

我冒昧地将.php部分从mypage.php移除,因为它没有实际用途,并使网址看起来不那么漂亮。

RewriteEngine On
RewriteBase /
RewriteRule ^mypage$ /index.php?this=that&this=that&whatevs=this&that=&id=5 [L,QSA]
相关问题