4

Assuming my site will do something if the URL looks like this mysite.com/index.php?myparam=test

In .htaccess, I added the following line:

#RewriteRule ^([a-z]+)$ /index.php?myparam=$1 [L]

Which works great! URL mysite.com/test will redirect accordingly and everything works

I would like to get rid of the dirty URL so that if someone keys in manually mysite.com/index.php?myparam=test he will be redirected to mysite.com/test and still works, without going into an infinite loop..

0

2 Answers 2

0

If you get the idea of "routing" where you have the mechanism translating parameters to URL and get the execution parameters from entered URL, if someone enters execution parameters manually, you redirect him to the URL you get from routing mechanism.

Some information about routing mechanism in symfony 1.4 framework:

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/05

I've wrote a routing mechanism for my university project in a couple of hours, so it is possible to have one. If not, the most popular [IMHO] routing library is Horde:

http://dev.horde.org/routes/

0

Ok after some further reading on the net and thanks to Salman's reply, I figured out the answer to my problem :)

the code below will rewrite the dirty url to clean one...

RewriteCond %{THE_REQUEST} ^.\?myparam=([a-zA-Z]+).

RewriteRule ^(.*)$ /%1? [R=301,L]

note that the question mark behind '/%1' is very very important because putting it there (on the redirect target) will clear the query string.

after that, the code below will redirect the clean url to the dirty one without changing the url(still remain clean)

RewriteRule ^([a-zA-Z]+)$ /index.php?myparam=$1 [L]

this won't cause an infinite loop due to the usage of THE_REQUEST which will only respond to your request and not server side redirect (i think)

you may need to read on mod_rewrite syntax guides to customize it for your own needs..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.