views:

32

answers:

1

I have my cakephp .htaccess files set up as in the cookbook and everything is working fine.

My web site currently has multiple domains, all of which point to the same site (e.g. www.site.com, www.site.co.uk). I'd like to set up a rule so that requests to www.site.co.uk/page are permanently redirected to www.site.com/page, etc.

I'm having trouble getting both rules to work together. Can anyone help me out?


EDITED TO INCLUDE FURTHER DETAILS:

Here is the .htaccess file in my web root:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on

    # Force domain to be www.atdbio.com
    RewriteCond %{HTTP_HOST} !^www\.atdbio\.com$
    RewriteRule ^(.*)$ http://www.atdbio.com/$1 [R=permanent,NC]

    # For CakePHP   
    RewriteCond %{HTTP_HOST} ^www\.atdbio\.com$ 
    RewriteRule    ^(.*)$ app/webroot/$1    [NC]
</IfModule>

I also have a separate CakePHP app in a subdirectory: tbgroup. Here is the .htaccess file (tbgroup/.htaccess):

<IfModule mod_rewrite.c>
   RewriteEngine on

   # For CakePHP
   RewriteRule    ^(.*)$ app/webroot/$1    [NC]
</IfModule>

Everything works as fine: www.atdbio.co.uk is redirected to www.atdbio.com, www.atdbio.co.uk/page is redirected to www.atdbio.com/page. CakePHP works fine. The only problem is www.atdbio.co.uk/tbgroup is not redirected to www.atdbio.com/tbgroup - it remains as www.atbio.co.uk/tbgroup (and CakePHP works fine).

Try it out on the live site if you like (www.atdbio.com or www.atdbio.co.uk).

+1  A: 

I believe that you've pointed out the answer in the permanent redirection link in your question.

It's really not related to cakephp. It's just mod-rewrite issue. You have yo put this code in your .htaccess file (under /app/webroot)

rewritecond %{http_host} ^(www.)?site.co.uk [nc]
rewriterule ^(.*)$ http://site.com/$1 [r=301,nc]
Nik
Thanks. This solves the problem (I've omitted the (www.)? as I prefer to keep the www). However, I now have a problem with a separate CakePHP app in a subdirectory that I didn't mention. I have modified my post to include the details.
Tomba
I think the problem is because tbgroup is a real directory and the .htaccess in the parent directory is not used. Tro to move # Force domain to be www.atdbio.com part in the tbgroup/.htaccess
Nik
Thanks - I seem to have got it working now.
Tomba