Forum Moderators: phranque

Message Too Old, No Replies

htaccess url redirection

         

asantos

8:37 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Hi, i have 2 domains:

1) abcdef.com
2) qwerty.com

qwerty.com is actually going to be redirected to:
qwerty.abcdef.com as a subdomain

What preg instruction should i implement on my htaccess file in order to accomplish the next examples?

* qwerty.com redirects to qwerty.abcdef.com

* qwerty.com/test redirects to qwerty.abcdef.com/test

* qwerty.com?var=123 redirects to qwerty.abcdef.com?var=123

and so on...

Thanks.

g1smd

12:02 am on Aug 9, 2007 (gmt 0)

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



It can all be done in two lines of code. That code will cater for all filenames.

It is essentially the same code as redirects non-www to www as previously posted.

asantos

3:15 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



can you please provide me those 2 lines of code?
thanks!

RDWest2005

3:37 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule .* [domain.com...] [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule .* [domain.com...] [L,R=301]

the first rule is for non www to www
So i think it will work by adding the second rule so you redirect the www to new domain also

~R

asantos

3:51 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



thanks, that one is better than the one i just implemented:


Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

RDWest2005

3:55 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



Glad to help,
My post before yours has me stumped...
I can't figure out how the src is passed to dst for URL alias :(

~R

g1smd

4:04 pm on Aug 9, 2007 (gmt 0)

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



This is it:

# Enable Rewrite options
Options +FollowSymLinks
RewriteEngine on

# Redirect www and non-www on other domain to subdomain over here
RewriteCond %{HTTP_HOST} ^(www\.)?qwerty\.com$ [NC]
RewriteRule ^(.*)$ http://qwerty.abcdef.com/$1 [L,R=301]

# cater for www on sub-domain (just in case it does reesolve) to avoid duplicate content
RewriteCond %{HTTP_HOST} ^www\.qwerty\.abcdef\.com$ [NC]
RewriteRule ^(.*)$ http://qwerty.abcdef.com/$1 [L,R=301]

Rewrite code does exactly what you program it to do... not what you might hope to achieve. Every symbol needs to be carefully checked and you need to cater for all forms of input URL - expected and unexpected.

The code above does not cater for cases where the port number may have been appended, such as if a user looks at your site through a proxy.