views:

15

answers:

1

Hello,

I'm trying to make a redirect from a non-www version of the link to the www one. Its working fine for something like http://mywebsite.com but it fails for a request like http://mywebsite.com/artists/metallica/ or even a complex one. The whole .htaccess file is bellow. Any clues?

Options +FollowSymLinks

RewriteEngine On

RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-f 

RewriteCond %{REQUEST_URI} !(.*).html

RewriteCond %{REQUEST_URI} !(.*)/$ 

RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L,R=301]

RewriteRule ^artists/([^/-]+)-p([^/]+)/$ /artists.php?l=$1&p=$2 [QSA,L] 

RewriteRule ^artists/([^/]+)/$ /artists.php?l=$1 [QSA,L] 

RewriteRule ^submit/$ /submit.php [QSA,L] 

RewriteRule ^users/$ /users.php [QSA,L]  

RewriteCond %{THE_REQUEST} ^.*/index.php 

RewriteRule ^(.*)index.php$ http://www.mywebsite.com/$1 [R=301,L]
+1  A: 

Try this rule:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

But make sure that you put this rule in front of those rules that just do an internal rewrite. Otherwise an already internally rewritten rule might get redirected externally.

Gumbo
Thanks Gumbo. Seems to be ok.
Psyche