Forum Moderators: phranque

Message Too Old, No Replies

subdomain and subdomains folders redirecting htaccess

using htaccess for subdomains and subdomains folders redirection

         

BlueBulb

5:42 am on Aug 23, 2012 (gmt 0)

10+ Year Member



Hello guys, need help with .htaccess files on redirect rules.

Wishes to redirect abc.example.com to another.example2.net/example.html
and also inside the abc folder, there's 2 sub folders.
xyz1 and xyz2.

eg. abc.example.com/xyz1 is redirected to another.example3.com ?
and abc.example.com/xyz2 ish redirected to another2.example4.com/file.html ?


to break it down

abc.example.com -> another.example2.net/example.html
abc.example.com/xyz1 -> another.example3.com
abc.example.com/xyz2 -> another2.example4.com/file.html

redirects using .htaccess file. [R=301,L]


here's the code I placed inside my subdomain folder "abc"

RewriteEngine On

RewriteBase /abc/

RewriteRule (.*) http://another.example2.net/example.html$1 [R=301,L]
RewriteRule xyz1(.*) http://another.example3.com$1 [R=301,L]
RewriteRule xyz2(.*) http://another2.example4.com/file.html$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]


However I am getting error, when I tried abc.example.com/xyz1 it brings me to [another.example2.net...] instead of [another.example3.com...]

how do I solve the above issue?

Hope to get some reply :)

Thanks in advance

g1smd

6:37 am on Aug 23, 2012 (gmt 0)

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



Let's see you best effort code so far. Describe the problems you are having with it.

There's more than 20 000 prior threads here with various redirect examples in. They are archived for your convenience.

BlueBulb

6:44 am on Aug 23, 2012 (gmt 0)

10+ Year Member



subdomain redirect rule is conflicting with the folders redirect rule

stated on my first post, hence only the subdomain is redirected properly instead of the other two folders inside the subdomain.

any idea? :(

lucy24

8:50 am on Aug 23, 2012 (gmt 0)

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



Have you figured out yet that example.com is the ONLY thing that works? If you need more of 'em, go to example.net or example.org or example.xyz or...

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

This rule, with conditions, is meaningless in its current location. If it is intended to intercept requests for images and so on that actually exist, it has to go before all other Rules. But it's not the ideal form anyway. Instead, write each Rule to include only the extension the Rule specifically applies to. Or no extension, if that's your preferred form.

RewriteRule (.*) http://www.example.two/example.html$1 [R=301,L]
RewriteRule xyz1(.*) http://www.example.three$1 [R=301,L]
RewriteRule xyz2(.*) http://www.example.four/file.html$1 [R=301,L]

Gotta say that some of those rules look like gibberish, even without the floating domain names.

Rule 1: capture ALL requests, regardless of domain name or extension, and send to
www.example.two/example.html{blahblah}
where {blahblah} is the original request. Why is it getting attached to the URL after "example.html"? I also don't understand why this Rule doesn't result in an infinite loop. Is the htaccess file located in a directory where requests for www.example.two will never see it?

Rule 2: if request contains string "xyz1", then capture anything that might happen to come after xyz1 and send to
www.example.three{blahblah}
regardless of whether the captured part begins with a slash.

Rule 3: same, but this time look for a different string, and attach the overflow to www.example.four/file.html. So again, as in Rule 1, attaching text in a location where nothing should be attached.

I get the impression you don't actually want the $1 captures at all. What are they there for?

However I am getting error, when I tried abc.example.com/xyz1 it brings me to http://www.example.two/example.htmlxyz1 instead of http://www.example.three

Yes, that's exactly what your Rules are set up to do. Rule 1 has no conditions, so it will always redirect all requests: in this case, from www.example.com/xyz1 to www.example.two/example.htmlxyz1. There is no mechanism to prevent Rule 1 from executing, so you will never get past it. What happens next depends on your error-handling functions.

BlueBulb

9:39 am on Aug 23, 2012 (gmt 0)

10+ Year Member



Hello lucy, thx for the response.

Ya, I realize that is the only thing that works.

Anywhere I can read up on conditions regarding rule 1?
I am kinda new to this. :(


just wanted to redirect a subdomain follow by 2 folder(links) which resides in the subdomain folder

lucy24

8:50 pm on Aug 23, 2012 (gmt 0)

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



Start with the most specific rule. Work down to the most general. Any rule that applies only to certain exact filenames should go at the beginning.

At the very end go the mopping-up rules: the /index.html redirect and the with/without www redirect.

Go read the last half dozen threads in this forum. You will see that it is mostly the same question over and over. Only the names have been changed.