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 5 of 5
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts

    Redirect URL keeping the query string

    I'm trying to redirect all requests to page1.php to page2.php keeping whatever querystring there is intact - but I cant seem to make it work.

    I've tried
    Code:
    RewriteRule ^page1.php page2.php?{query_string} [PT]
    and
    Code:
    RewriteRule ^page1.php?(.*) page2.php?$1 [PT]
    Everything I've found on google is about removing the querystring but I want to keep it.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    A couple things that might help.

    http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
    'qsappend|QSA' (query string append)
    This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

    http://forums.searchenginewatch.com/...ead.php?t=3925
    RewriteCond %{QUERY_STRING} ^cat\=([^&]+)\&product_id\=([^&]+)$

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Looks like I got it sorted - just dropped the ? from RewriteRule ^page1.php?(.*) page2.php?$1 [PT]
    Last edited by NancyJ; 04-19-2007 at 05:56 PM.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    can anyone give me a good linky on the various flags (eg. [PT]) that go at the end of the directive. I know what some of them mean but I'd like to see a comprehensive list

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    The manual for mod_rewrite, linked above, has them all.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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