301 redirect to mod_rewrite URL

Discussion in 'Apache' started by dpak, Oct 24, 2005.

  1. #1
    Hi,
    I'm looking to do a 301 redirect using a regular expression.

    I tried adding a "RedirectMatch permanent" entry to my .htaccess file, but it didn't seem to work.

    Can somebody tell me if my logic is right here?

    Basically, I want it so that if someone tries to access the script directly, e.g. somepage.php?id=1, they get a 301 redirect to the "static" page (somepage1.html). The only thing is that the static page (somepage1.html) is really just a rewrite rule back to that original script. (if you're following me)

    RedirectMatch permanent ^somepage.php\?id=(.+)$ http://www.mysite.ca/somepage$1.html

    RewriteRule ^somepage(.+)\.html$ /somepage.php?id=$1 [L]

    So, the RewriteRule works fine, but the RedirectMatch rule isn't returning a 301 response for "http://www.mysite.ca/somepage.php?id=1".

    I've also tried doing it all with mod_rewrite by replacing the RedirectMatch rule with this RewriteRule...

    RewriteRule ^somepage\.php\?id=(.+) http://www.mysite.ca/somepage$1.html [R=301,L]

    Anyone know if what I'm trying to do is possible? and if so, what I've done wrong?

    Thanks!
     
    dpak, Oct 24, 2005 IP
  2. dpak

    dpak Peon

    Messages:
    111
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Also, I'm testing to see if I get a 301 response back using this tool:

    http://www.wannabrowser.com

    It looks like it should show me the 301 response, but I'm starting to wonder if it would actually show that response.
     
    dpak, Oct 24, 2005 IP