mask URL (with parameters) with htaccess

1.7k views Asked by At

i need to mask a long, stupid php URL with a relatively simple URL with htaccess. For example, i need to mask -

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

with this simple URL -

http://mysite.com/mypage.php

I know php can do the stuff very easily by fetching the content of that page and displaying it. But in my conditions, there are some problems with ajax calls and some other things.

Moreover, i prefer to use htaccess. I did some research but htaccess codes are very confusing to me.

2

There are 2 answers

0
Gerben On BEST ANSWER

I took the liberty of removing the .php part from mypage.php as it has no real use, and makes the url look less pretty.

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

So you only want redirect http://mysite.com/index.php?this=that&this=that&whatevs=this&that=&id=5 to http://mysite.com/mypage.php?

Then use this 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]