SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Redirect /page.php?page=about to /about/

  1. #1
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirect /page.php?page=about to /about/

    Hi,

    What would my 301 redirect be if I wanted to redirect users from /page.php?page=about to /about/ ?


    Thanks for any help

  2. #2
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Redirect 301 /page.php?page=about /about/

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi W1LL,

    Unfortunately that doesn't seen to work for me

    Can I PM you the link?

  4. #4
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes of course you can, I'll take a look for you.

  5. #5
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just thought, you might need to include the whole address to forward to:

    Code:
    Redirect 301 /page.php?page=about http://www.example.com/about/

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,315
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    iv2,

    I don't think that mod_alias can look at the query string (certainly it can't use a match ... without using RewriteMatch) so I'd rely on mod_rewrite with:
    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^page=about$
    RewriteRule page\.php$ about/ [R=301,L]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    DK,

    I'm using this...

    Code:
    RewriteCond %{QUERY_STRING} ^page=about$
    RewriteRule page\.php$ http://www.test.com/about/ [R=301,L]
    but when it repoints, it gives me http://www.test.com/about/?page=about sadly

    Do you know why this is the case?


    Thanks again

  8. #8
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,997
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Side question:
    Can RewriteCond be used with Redirect (or RedirectMatch)? Or only with RewriteRule and R flag?

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey stomme,

    This is in my 'htaccess' file.

    It works, but then appends ?page=about to the redirected address.

  10. #10
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,997
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    You don't have any other rules (rewrite, etc) anywhere else?

    I thought you needed the QSA flag to append query strings!

  11. #11
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,997
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Aha:
    http://www.simonecarletti.com/blog/2...-query-string/

    However, if you don’t append something new, then the original query is passed through the rules unchanged by default.
    If you want to discard the original query string you must append an empty question mark at the end of the rule. Let’s call it the query string not append or query string discard flag.
    Bleh, so if this guy is right it should be
    Code:
    RewriteCond %{QUERY_STRING} ^page=about$
    RewriteRule page\.php$ about/? [R=301,L]
    But, I'm not sure.

  12. #12
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, that ? did the job!!! Brilliant, stomme many thanks for your efforts.

  13. #13
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,997
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Shoot, means I gotta change mine now too : )

  14. #14
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,315
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    poes,

    Aw, you didn't find that ? (kill the query string) answer in my signature's tutorial? Hmmm, there must be TOO MUCH information there! Oh, well, it was the CORRECT answer!
    Quote Originally Posted by Stomme poes View Post
    Side question:
    Can RewriteCond be used with Redirect (or RedirectMatch)? Or only with RewriteRule and R flag?
    RewriteCond is a part of Apache's mod_rewrite while Redirect (et al) are part of Apache's (core) mod_alias. In other words, RewriteCond cannot be used with Redirect or RedirectMatch. In fact, any and all mod_alias directives are acted upon BEFORE any mod_rewrite directives (priority).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  15. #15
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Eeeek, sorry dklynn.

    Will pay closer attention next time

    Just glad I got it resolved

  16. #16
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,997
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Aw, you didn't find that ? (kill the query string) answer in my signature's tutorial? Hmmm, there must be TOO MUCH information there! Oh, well, it was the CORRECT answer!
    I stupidly sought only what I knew had something to do with it... and remained sitting at the [QSA] flag section of the tut. I did the same thing at apache.org : ( looked at the flags.

Bookmarks

Posting Permissions

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