SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    htaccess - why doesn't this 301 redirect work?

    I have an htaccess file in the root directory of a site, and it contains a number of 301 redirects, most of which work fine. But some do not. Here's an example:

    Redirect 301 /page/?qs=query_string http://www.domain.com/page.html

    Please note that, in this example, "/page/" is an actual page in and of itself (there's a document "/page/index.php"). When I put "/page/?qs=query_string" in the location window of my browser, nothing in the URL changes, and the page displays the "/page/" content as if there were no query string in the URL. The second part of that is actually to be expected, since the page isn't looking for the variables in the "bad" query string, but why isn't it redirecting?

    Suffice it to say that I'm not an expert on redirects, so thanks for any help!

  2. #2
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, it appears I have to use mod_rewrite, as 301 redirects can't deal with query strings? I'll try that.

  3. #3
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This worked:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} =qs=query_string
    RewriteRule ^page/$ /page.html? [L,R=301]

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,084
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Indeed, simple redirects don't work on / ignore the query string, you need mod_rewrite for that. Nice catch!
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •