homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

redirecting all aliases to subdomain
.htaccess rewrite rules for redirecting all aliases to subdomain?

 11:08 pm on May 22, 2012 (gmt 0)

I have a site that was previously located at www.example.com

I'm trying to now redirect all www.example.com/whateverpage requests to online.example.com/whateverpage instead.

The redirects are working in flipping things over to the online.mysite.com subdomain, but are redirecting to the non-aliased versions, i.e.


goes to:


instead of:


as desired.

furthermore there is apparently some duplicate content issues,

I'd imagine this is related to my incompetence working with .htaccess and rewrite rules in general, but alas I'm lost and hoping for some tips. My rewrite rules look like:

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://online.example.com/$1 [R=301,L]

The initial RewriteCond's in the default .htaccess files seem to reference that sort of thing (I think?), but commenting them out/messing around with them doesn't seem to do the trick...

Any suggestions much appreciated!


[edited by: incrediBILL at 2:38 am (utc) on May 23, 2012]
[edit reason] fixed URL format [/edit]



 11:18 pm on May 22, 2012 (gmt 0)

Placing the external redirect after the internal rewrite exposes the previously rewritten path as a new URL back out on to the web.

The order of your three rulesets is exactly backwards to what it should be.

It should be:
- index file redirect
- subdomain redirect
- internal rewrite

Additionally, the pattern
!^online.example.com$ should be !^(online\.example\.com)?$
Escape the literal periods in RegEx patterns.
The ( ) ? addition prevents a redirect loop for pure HTTP/1.0 requests.


 10:07 pm on May 23, 2012 (gmt 0)

Thank you so much g1smd

If you re coming to Pubcon Las Vegas I would love to buy you a drink or 10 :-) ?


 10:15 pm on May 23, 2012 (gmt 0)

I assume that fixed it then. Great!

Sadly, stuck in the UK. Never been to a US PubCon.

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