Welcome to WebmasterWorld Guest from 54.166.112.74

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect Domain to SubDir Without Screwing Other Redirects

htaccess is fun... well maybe not

   
5:41 pm on Mar 2, 2012 (gmt 0)



I've installed WordPress in a SubDir (/content) and am using pathinfo instead of mod_rewrite to handle pretty URLs (because WP's mod_rewrite borks my site's existing rewrites) and so ordinarily it would be a simple matter of redirecting visitors of my domain to the SubDir.

But several other domains are attached to my site, so I use some code that makes them all go to
http://www.mysite.com 
(i.e. requests for
http://www.coosite.com 
or
http://coosite.com 
would become
http://www.mysite.com
). This avoids Google's duplication penalty and ensures that "www" is always used (I don't like that but I need it for license reasons).

The code I use for this is simple and clean (hopefully).

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


Now I can't figure out how to then do a rewrite that directs
http://www.mysite.co.uk 
visitors to wordpress in my /content dir, at least not without breaking the above multi-domain redirect. I tried putting this below and it sent the server slow and crashing.

RewriteCond %{REQUEST_URI} !content/
RewriteRule ^(.*)$ content/$1 [L]


On top of that I also want to ensure that any calls to index.html or index.shtml are directed to the subdir as well. What's the best way of doing this?
6:19 pm on Mar 2, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The index redirect can be done with a separate RewriteCond and RewriteRule placed before the canonical ruleset.

In your existing RewriteCond change
!^www\.example\.co.uk [NC]
(why escape only two of the three periods?) to this new pattern
!^(www\.example\.co\.uk)?$
and remove both the [NC] flag and the second RewriteCond.
8:00 am on Mar 3, 2012 (gmt 0)



Putting the subdir redirect before the HTTP_Host call just causes the server to hang, the same as if I were to put it after.

RewriteCond %{REQUEST_URI} !content/
RewriteRule ^(.*)$ content/$1 [L]

Some people have suggested to use something like this:

RewriteRule ^(/)?$ content [L]

But ideally when people visit I want them to see the /content under the domain itself and not a URL like [mysite.co.uk...] . But then I'm affraid that forcing that might break existing and or future redirects.. ugh. what a headache :) .
8:07 am on Mar 3, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Let's see the code you are talking about (with corrections and additions as noted above).
4:59 pm on Mar 4, 2012 (gmt 0)



I'm experimenting with Pathinfo instead of rewrite's for WP so that I can hopefully avoid this :) .