开发者

cakephp .htaccess with multiple domains

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.site.com
    RewriteCond %{HTTP_HOST} !^www\.site\.com$
    RewriteRule ^(.*)$ http://www.site.com/$1 [R=permanent,NC]

    # For CakePHP   
    RewriteCond %{HTTP_HOST} ^www\.site\.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.site.co.uk is redirected to www.site.com, www.site.co.uk/page is redirected to www.site.com/page. CakePHP works fine. The only problem is www.site.co.uk/tbgroup is not redirected to www.site.com/tbgroup - it remains as www.site.co.uk/tbgroup (and CakePHP works fine).

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


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜