Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: Ocean10000 & incrediBILL & phranque

redirecting all aliases to subdomain

.htaccess rewrite rules for redirecting all aliases to subdomain?

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

10+ Year Member



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.

http://www.example.com/whateverpage

goes to:

http://online.example.com/?q=whateverpage

instead of:

http://online.example.com/whateverpage

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!

Thanks.

[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)

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



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)

10+ Year Member



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)

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



I assume that fixed it then. Great!

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

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month