Click to See Complete Forum and Search --> : Need help with a URL rewrite RegExp


dCyphr
January 18th, 2008, 12:53 AM
I have a url rewriter on my website and need help making a tight RegExp so I can reroute requests based on the domain name. My website has a root folder called "/userfiles" which is where all the sub websites go under. So the structure is like this:

/userfiles/site1
/userfiles/site2
/userfiles/site3

Say I have a domain called domain1.com that is supposed to go to /userfiles/site1/*.* and no where else. So what I want the result to be is like this:

http://www.domain1.com => http://www.domain1.com/userfiles/site1
http://domain1.com => http://domain1.com/userfiles/site1
http://ww2.domain1.com => http://ww2.domain1.com/userfiles/site1
http://www.domain1.com/ => http://www.domain1.com/userfiles/site1/
http://www.domain1.com/folder/test.htm => http://www.domain1.com/userfiles/site1/folder/test.htm
http://domain1.com/test.htm?param=abc => http://domain1.com/userfiles/site1/test.htm?param=abc
http://ww8.domain1.com/?param=123 => http://ww8.domain1.com/userfiles/site1/?param=123
http://www.domain1.com/userfiles/site1/folder/test.htm => http://www.domain1.com/userfiles/site1/folder/test.htm
http://www.domain1.com:8080/ => http://www.domain1.com:8080/userfiles/site1/
http://www.domain1.com:8443/folder/test.htm => http://www.domain1.com:8443/userfiles/site1/folder/test.htm
https://domain1.com/test.htm?param=abc => https://domain1.com/userfiles/site1/test.htm?param=abc

Can anyone see the pattern in here to make a solid RegExp? Below is an entry I put in my rewriter app, but that just sends anything that hits the root will rewrite it the new format carrying all its parameters:

<rewrite url="^(.*)/(\?.+)?$" to="$1/userfiles/site1$2" />

Can anybody help construct or start a single rule that can handle all my examples above specifically for domain1.com?

PeejAvery
January 18th, 2008, 08:17 AM
Why are you wasting your time scripting this? You need to alter your DNS zone file for this. In which case, you may have to contact your web host provider.