views:

75

answers:

2

I just migrated a site to an updated version, but want to put 301 redirects in place for some of the most common entry pages of the site to their counterparts

So here's the rule I'm adding to the .htaccess:

Redirect 301 /oldhomepage.htm http://www.thesite.com/

It sort of works, but it redirects to

http://www.thesite.com/?url=oldhomepage.htm

Is this some conflict with a CakePHP routing setting?

EDIT: Someone pointed out that it's probably an .htaccess conflict and indeed it is. CakePHP automatically creates an .htaccess file (which was in a child directory) that has the following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Is there any way I can easily have the best of both worlds and have my simple, per page 301 redirects and keep CakePHP's routing as well?

A: 

Why would you not use $this->redirect('http://www.thesite.com/', 301); in your controller?

bancer
Well, I'd totally do it from the cakePHP router if I could, but you might be misunderstanding my intent. In the client's old site they had some URL's like thesite.com/main.htm. On the new site I don't have a main.htm, so I want to make sure that links (especially google links) to main.htm are gracefully redirected to the new home page.
danieltalsky
+1  A: 

If all of the old URLs end with .htm, and none of your new URLs do, you could edit the CakePHP .htaccess file like so:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.htm$
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Tim Stone
Indeed none of the new url's do. Do I use this in combination with this:Redirect 301 /oldhomepage.htm http://www.thesite.com/?
danieltalsky
Yep. This modification should prevent the `?url=oldhomepage.htm`, so you can leave your original file as-is, and those redirects will behave correctly.
Tim Stone