Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post

    Mod rewrite with GET values on the url

    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.

  • #2
    New Coder
    Join Date
    Aug 2010
    Posts
    11
    Thanks
    0
    Thanked 1 Time in 1 Post
    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?
    Free Web Hosting - cPanel powered free web hosting

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post
    Quote Originally Posted by jphilipson View Post
    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

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post
    OK got this somehow working with this
    Code:
    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

    Code:
    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?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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:
    Code:
    RewriteRule ^([^\.]+)$ $1.php [QSA]
    And I honestly have no idea if that will work O.o
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    hernantz (09-08-2010)

  • #6
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    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:
    Code:
    RewriteRule ^([^\.]+)$ $1.php [QSA]
    And I honestly have no idea if that will work O.o
    haha, worked great.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by hernantz View Post
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post
    html files are working too.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •