Forum Moderators: phranque

Message Too Old, No Replies

non-www to www problem and rule conflict

htaccess rewriterule conflict www

         

bramley

8:17 pm on Jul 20, 2012 (gmt 0)

10+ Year Member



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


rediects ok at the root and for domain.com/directory/file

but not domain.com/directory/

Also, I must include the following rule :

RewriteRule ^index.php/([^/]+/)+index.php http://www.example.com/beijing/index.php [R=301,L]

But somehow there is a conflict with the non-www to www rule :(

Any help would be greatly appreciated. Thanks.

[edited by: incrediBILL at 10:32 pm (utc) on Jul 20, 2012]
[edit reason] exemplified URLs [/edit]

wilderness

8:27 pm on Jul 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This was answered (with syntax provided) just yesterday in another thread by g1smd.

bramley

9:23 pm on Jul 20, 2012 (gmt 0)

10+ Year Member



The first issue has spontaneously resolved.

But I have no idea about the conflict.

lucy24

10:13 pm on Jul 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The with/without www rule should be the very last of your redirects, after any specific rules.

g1smd

10:32 pm on Jul 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Never redirect to a named index file.

The canonical URL ends with a trailing slash.

bramley

11:13 pm on Jul 20, 2012 (gmt 0)

10+ Year Member



lucy24 - i'll double check but i think i tried that.

g1smd - i have to have that rule as without it I get 1000s of wierd urls indexed by Google (I don't know why, but this solves it).

Any idea why there is a conflict / how to avoid it ? Thanks.

bramley

1:29 am on Jul 21, 2012 (gmt 0)

10+ Year Member



lucy24 - i moved the order as you suggested and 2 hours on seems ok :)

Wont be till i look in WMT a few weeks later that I'll lnow for sure though (fingers crossed).

As soon as i have time I am moving this site from Joomla Junk CMS to my own which I have been using since the disaster last year.

lucy24

3:19 am on Jul 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh, and the second rule (the index.php one) should say

RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php http://www.example.com/ [R=301,L]

The Condition is to avoid an infinite loop caused by mod_dir silently rewriting to "index.php". You only want to redirect the people-- or robots-- who came in and asked for index.php by name. If it happens in other directories, not just the top level, your rule will need to become a teeny bit more complicated. But not much.

If you are having issues with google indexing bogus parameters (query strings) that's a whole nother question.