mobz
mobz

Reputation: 13

redirect all non www to www. for Cakephp site

Hi allm i'm having some issues in redirecting the non www pages to the www. pages for my cakephp site.

I've tried

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

but it doesn't seem to work.

My cakephp app resides in a subfolder. eg. www.domain.com/my.

i've added the above code to the root folder, www.domain.com/

any suggestions? thanks?

*update

This my .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On

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

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]

i'm getting an extra webroot/index.php?url= inserted into the url. Instead of www.domain.com/my/apple, i'm getting www.domain.com/my/webroot/index.php?url=apple

thanks to all once again.

Upvotes: 1

Views: 4284

Answers (4)

Jai
Jai

Reputation: 1

I have tried the below code below and it worked for me:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^gigsadda\.com$ [NC]
   RewriteRule ^.*$ http://www.gigsadda.com%{REQUEST_URI} [R=301,L] 
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Upvotes: 0

imo inyang
imo inyang

Reputation: 51

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]

Upvotes: 2

Fury
Fury

Reputation: 4776

if domain is .co.uk

<IfModule mod_rewrite.c> 
   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [NC] 
   RewriteRule ^.*$ http://www.domain.co.uk%{REQUEST_URI} [R=301,L]

   RewriteRule ^$ app/webroot/    [L]
   RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Upvotes: 2

wrdevos
wrdevos

Reputation: 2069

Your code is not quite right. See below.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!

RewriteRule ^$ webroot/    [L]
RewriteRule (.*) webroot/$1 [L]

Upvotes: 6

Related Questions