Forum Moderators: phranque
I've been setting up redirects from non-www to www in htaccess using the following rules -
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L] This works on the inner pages of my site, for example is i go to http://example.co.uk/page1.html i get redirected to http://www.example.co.uk/page1.html
However, the problem is with the homepage. When i go to http://example.co.uk/ i get redirected to http://www.example.co.uk/index.php
So i tried this -
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/ [R=301,L] Now when i go to http://example.co.uk/ i get redirected to http://www.example.co.uk/
Great, that's what i want but... when i go to http://example.co.uk/page1.html i also get redirected to http://www.example.co.uk/
Can any one point in the right direction please? I want it to redirect to http://www.example.co.uk/page1.html
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
Put all of your external redirects (those with "http://www.example.com" in the substitution URL and/or [R=301] flags) first, followed by all of your internal rewrites. End each rule with a [L] flag. Within each of these two groups (redirects and rewrites), order the rules from most-specific patterns and conditions to least-specific. This avoids unexpected operation and prevents 'exposing' your internal filepaths as URLs to the client.
Jim
I tried those but still getting the same. Inner pages are fine as in if i try a non www version of inner pages it'll redirect me to the www version. The home page problem still exists though, where it is redirecting me to index.php.
I'm quite new to this so i don't understand what you mean by "put all your external redirects".
I'm actually using Joomla for the website and it has it's own predefined rules for search engine friendly urls. I think this may be interferring. The rules are as follows -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/¦\.php¦\.html¦\.htm¦\.feed¦\.pdf¦\.raw¦/[^.]*)$ [NC]
RewriteRule (.*) index.php [L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Your new redirect rule must be placed ahead of your Joomla rewrite code. Otherwise, it will interfere.
Please look at this thread concerning Joomla mod_rewrite code [webmasterworld.com], as I don't want to have to repeat all that detail here. The modified code in that thread will be at least twice as fast as what Joomla has provided to you...
Jim