homepage Welcome to WebmasterWorld Guest from 204.236.255.69
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirect Domain to SubDir Without Screwing Other Redirects
htaccess is fun... well maybe not
ispreview




msg:4424212
 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?

 

g1smd




msg:4424230
 6:19 pm on Mar 2, 2012 (gmt 0)

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.
ispreview




msg:4424425
 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 :) .

g1smd




msg:4424427
 8:07 am on Mar 3, 2012 (gmt 0)

Let's see the code you are talking about (with corrections and additions as noted above).

ispreview




msg:4424736
 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 :) .

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved