I have two websites, an old one and a new one. I have set up redirects in the old site to point to pages on the new site. However, I'm seeing some strange behavior on some of the redirects.

E.g. I have the following redirect in the .htaccess on the old site:

<IfModule mod_rewrite.c>
    RewriteEngine On

    Redirect 301 /car-finance/car-loan-comparison http://www.newsite.com/car-finance/car-finance-comparison

When I go to the old site to /car-finance/car-loan-comparison I'm being redirect to the new site on the path /car-finance/car-loan-comparison resulting in a 404.

For some reason the old path is applied to the domain in the redirect instead of the redirected path.

This is what I have in the .htaccess of my newsite:

<IfModule mod_rewrite.c>
    RewriteEngine On

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

Any ideas much appreciated,

  • On the new site, you have a rewrite rule to go from newsite.com to www.newsite.com. That's because newsite.com and www.newsite.com DNS record point to the same server and you want to keep it pretty with the www? The old site then is a totally different domain? – ETL Apr 21 '13 at 22:43
  • Do you have any generic redirects for the old site to the new site? – becomingwisest Apr 21 '13 at 23:40
  • @ETL; From oldsite I'm always redirecting to the www version of newsite. I assume this means that the www redirect on newsite never gets triggered. – Luke Apr 22 '13 at 0:39
  • @becomingwisest; The last redirect on oldsite is a redirect of / to newsite.com if that is what you mean with a 'generic' redirect. When I take it out it doesn't make a difference. – Luke Apr 22 '13 at 0:40
  • 1
    BTW: Redirect does not need mod_rewrite (it's part of mod_alias), so you don't need to put it in an "ifModule mod_rewrite" block. – Krist van Besien Apr 22 '13 at 5:07

Use the rewrite logging option to get some detailed output of what it is doing; you'll be able to see where the problem is, and mostly likely exactly why it is happening:

Add these to your rewrite config:

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

Don't forget to disable it afterwards or you'll chew up your disk space and reduce performance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.