Forum Moderators: phranque

Message Too Old, No Replies

Redirect multiple sites to 1 on same .htaccess

Need help to redirect

         

edhen

3:34 am on Mar 7, 2010 (gmt 0)

10+ Year Member



I Have tried multiple ways to achieve my request but all has failed and as i have no knowledge about htaccess codes (apart from the research i have done) its becoming frustrating. My goal is to have

(1)
http://Site.com

(2)
http://Site.com.au

(3)
http://www.Site.com


all redirect to

http://www.Site.com.au


At one stage I had 1 and 3 work (I think, well i know 2 examples had worked) but atm I'm clueless and in need off help

Thank you,

jdMorgan

5:22 am on Mar 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best-effort code as a basis for discussion.

Thanks,
Jim

edhen

7:35 am on Mar 7, 2010 (gmt 0)

10+ Year Member



Options +FollowSymLinks
RewriteEngine On

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

works for example 1 and 2 but not 3... i didnt post the code in first post because i changed it so many times it was hard to backtrack... but i know that code gave that result. There was another code that i did which reulted in 3 working but the others wouldn't or i would keep getting redirection loop etc.. but i forgot what those codes or how i implemented them.

[edited by: jdMorgan at 6:27 pm (utc) on Mar 7, 2010]
[edit reason] example.com [/edit]

g1smd

7:52 am on Mar 7, 2010 (gmt 0)

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



This thread from yesterday should have many clues...

[webmasterworld.com...]

edhen

9:51 am on Mar 7, 2010 (gmt 0)

10+ Year Member



Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule ^(.*)$ http://www.example.com./$1 [L,R=301]


seemed to work fine so thanks for that.

[edited by: jdMorgan at 6:27 pm (utc) on Mar 7, 2010]
[edit reason] example.com [/edit]

g1smd

6:15 pm on Mar 7, 2010 (gmt 0)

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



That should be fine.

It's a question that gets asked almost every day. :)

jdMorgan

6:32 pm on Mar 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It will be fine on name-based virtual hosting. If on IP-based hosting, then you could get an HTTP/1.0 request without a Host header, and that would cause a rather nasty 'infinite' redirection loop. So if you're on IP-based hosting, or might be at some future time, I'd suggest:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com./$1 [L,R=301]

As warned about in the cited thread, there's more to getting a proper solution than just getting the code to be valid; The code needs to fit your exact server environment and your desired application.

Jim

edhen

9:31 pm on Mar 7, 2010 (gmt 0)

10+ Year Member



Thanks i'll keep that in mind.. this was only a problem and had to be sorted as all addresses had referred to the same files although logins etc seemed to not want to co-operate with different addresses... i searched google and visited number of places to find little about my goal.. places i visited didn't really explain on how to implement multiple rules without affecting another etc. then it really started to get confusing and as a beginner php coder to recently learning alot in php while learning a whole new code base is something i was not ready for right now... althogh i gather htaccess codes might be simple and looking at the code now kinda gives me an idea of whats being said but the only thing i don't understand is that if i add another condition it wouldn't had done what i gathered it should do (as if it would skip that condition or do something completely different or just get errors).. as in php a if else statement would had been alot simpler for my skills

g1smd

9:38 pm on Mar 7, 2010 (gmt 0)

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



The problem with .htaccess is in thinking about it as a program. It's not.

It's server configuration code, and each Apache module scans it in turn following only the directives that apply to it, and does so for each URL request received from the web.