www.webdeveloper.com
Results 1 to 3 of 3

Thread: 301 Redirect for Query Strings

  1. #1
    Join Date
    Jun 2005
    Location
    London, UK
    Posts
    191

    301 Redirect for Query Strings

    OK, I have a new redirect question. I found that for pages with a query string, the normal 301 redirect doesn't work, so I need a couple of rewrite rules for that, urgently.

    Our old website was really badly made, so almost every page is like http://www.example.com/more_info.asp?current_id=39. I have a need for two types of rule:

    1. To redirect a specific ID to a specific page.
    Code:
    http://www.example.com/more_info.asp?current_id=9
    
    // To this:
    http://www.example.com/page.php
    2. If possible, to redirect a range of IDs to a specific page.
    Code:
    http://www.example.com/more_info.asp?current_id=10
    http://www.example.com/more_info.asp?current_id=11
    http://www.example.com/more_info.asp?current_id=12
    ...
    http://www.example.com/more_info.asp?current_id=19
    
    
    // All of the above to this:
    http://www.example.com/page.php

  2. #2
    Join Date
    Jun 2005
    Location
    London, UK
    Posts
    191
    Does anybody know how to do this?

  3. #3
    Join Date
    Jun 2005
    Location
    London, UK
    Posts
    191
    Well, it took me days of searching, but this is how to 301 redirect a URL with a query string (and lose the query string):

    Code:
    RewriteCond %{QUERY_STRING} ^id=78$
    RewriteRule ^oldpage\.php$ http://www.example.com/newpage/? [R=301,L]
    This will redirect as follows:

    http://www.example.com/old.php?id=78
    http://www.example.com/new/

    It's essential to add the ? at the end of the new redirect URL in the rewrite rule. If you omit this question mark, the old query string will be carried over to the new URL. I still can't figure out why though; the purpose of a question mark here is confusing to me (any answers greatly appreciated).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles