Mod rewrite and 301 redirect problem

Discussion in 'Apache' started by fxchain, Jun 5, 2008.

  1. #1
    Hello all,

    I am having issues doing 301 redirects after rewriting URLs. It adds queries at the end of the URL after redirecting.

    http://www.thedomain.com/about/sitemap.php
    should 301 redirect to:
    http://www.thedomain.com/site-map.html
    but it redirects to:
    http://www.thedomain.com/site-map.html?page=about/sitemap.php
    and gives a 404

    This is the .htaccess code:
    --------------------------------------------
    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^www\.thedomain\.com [NC]
    RewriteRule ^(.*)$ http://www.thedomain.com/$1 [R=301,L]

    #Rewrites page.shtml as index.php?page
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteCond %{REQUEST_FILENAME} !-d [NC]
    RewriteRule ^(.+)$ index.php?page=$1 [QSA]

    #301 map for new CMS site
    redirect 301 /about/sitemap.php http://www.thedomain.com/site-map.html
    --------------------------------------------


    Any ideas?
     
    fxchain, Jun 5, 2008 IP
  2. mergemedia

    mergemedia Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mergemedia, Jun 5, 2008 IP
  3. fxchain

    fxchain Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Still same result with:

    RedirectPermanent /about/sitemap.php http://www.thedomain.com/site-map.html


    :(
     
    fxchain, Jun 5, 2008 IP
  4. fxchain

    fxchain Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    this is not working either:

    RedirectMatch permanent ^/about/sitemap\.php$ http://www.thedomain.com/site-map.html
     
    fxchain, Jun 5, 2008 IP
  5. fxchain

    fxchain Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Took me all day, but I figured it out!
    I had to use RewriteRule to make it work:

    -----------------------------------------------
    RewriteEngine On
    RewriteBase /

    RewriteRule ^about/sitemap\.php$ site-map.html [R=301,L]
    [add as many 301 redirect as you want here]

    RewriteCond %{HTTP_HOST} !^www\.thedomain\.com [NC]
    RewriteRule ^(.*)$ http://www.thedomain.com/$1 [R=301,L]

    #Rewrites page.shtml as index.php?page
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteCond %{REQUEST_FILENAME} !-d [NC]
    RewriteRule ^(.+)$ index.php?page=$1 [QSA]
    -----------------------------------------------

    Hope this post helps someone out.

    Cheers
     
    fxchain, Jun 5, 2008 IP