...

View Full Version : Mod rewrite with GET values on the url



hernantz
09-08-2010, 01:18 AM
Hi, i want to get this url http://localhost/play?t=12 to be converted into http://localhost/play.php?t=12. How to do it?

Also it is needed that if the user types http://localhost/play.php?t=12 it should work too.

Thanks in advance.

jphilipson
09-08-2010, 09:07 AM
Does this need to be dynamic, or just for a single URL? If just a single URL the following will work.

RewriteEngine On
RewriteRule ^play?t=12 /play.php?t=12 [L]

If I understand correctly?

hernantz
09-08-2010, 01:24 PM
Does this need to be dynamic, or just for a single URL? If just a single URL the following will work.

RewriteEngine On
RewriteRule ^play?t=12 /play.php?t=12 [L]

If I understand correctly?

OH forgot that, it has to be dynamic, 12 may change to 14, 2, or 1000

hernantz
09-08-2010, 03:41 PM
OK got this somehow working with this

RewriteEngine On
RewriteRule ^play$ play.php [QSA]
[QSA] seems to be the key to get the GET values working.

Now one more question.
I have several links that i would like to also like to remove the php, like login.php, register.php, upload.php....etc
Should i get a RewriteRule for each


RewriteRule ^login$ login.php [L]
RewriteRule ^logout$ logout.php [L]
RewriteRule ^register$ register.php [L]

or is there a unique rule to get all those php extensions removed?

Fou-Lu
09-08-2010, 05:56 PM
QSA is used to directly forward the querystring. Its very handy, especially with variable querystring variables.

The only rule I can think of is a poor solution otherwise. It would essentially map any non-extension to a 'hopeful' PHP page. That would look something like:


RewriteRule ^([^\.]+)$ $1.php [QSA]

And I honestly have no idea if that will work O.o

hernantz
09-08-2010, 06:29 PM
QSA is used to directly forward the querystring. Its very handy, especially with variable querystring variables.

The only rule I can think of is a poor solution otherwise. It would essentially map any non-extension to a 'hopeful' PHP page. That would look something like:


RewriteRule ^([^\.]+)$ $1.php [QSA]

And I honestly have no idea if that will work O.o

haha, worked great.

Fou-Lu
09-08-2010, 07:34 PM
haha, worked great.

Nice.
Make sure you test it with a page that has a .extension on it as well, to make sure it doesn't try mapping mypage.html to mypage.html.php. That would be bad. The regex is very primitive, but all it does it accepts something that doesn't contain a period in it.

hernantz
09-08-2010, 08:52 PM
html files are working too.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum