Forum Moderators: phranque

Message Too Old, No Replies

Reroute to folder based on url, not domain name

         

ambaxter

6:23 pm on Apr 20, 2011 (gmt 0)

10+ Year Member



Hello All,

I'm using this in my htaccess:

RewriteCond $1 !^folder2/
RewriteCond %{HTTP_HOST} ^www\.domain2\.com
RewriteRule (.*)/folder2/$1 [L]

Is there any way to use a different condition based on the path accessed (and subsequent children) to route to the contents of the alternate folder?

For example, I want to use this script (or something similar) on several virtual sites that will share a common domain name.

I'd like www.domain1.com/website/one to point to /folder1 on the server and www.domain1.com/website/two to point to /folder2 on the server.

I've tried using the condition for REQUEST_URI but that didn't seem to work.

g1smd

8:10 pm on Apr 20, 2011 (gmt 0)

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



You need to test THE_REQUEST as it is that which looks at what the browser actually requested.

The REQUEST_URI pointer can be modified by subsequent internal rewrites and may not reflect what the external request actually was.

ambaxter

4:33 am on Apr 21, 2011 (gmt 0)

10+ Year Member



I tried THE_REQUEST and it didn't work either. It breaks the reroute code and throws a 404.

Here's what i have

RewriteCond $1 !^folder/
RewriteCond %{THE_REQUEST} ^www\.domain\.com/website/one
RewriteRule (.*)/folder/$1 [L]

g1smd

7:13 am on Apr 21, 2011 (gmt 0)

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



That code can never work. The pattern is completely wrong.

The RegEx pattern for THE_REQUEST needs to match the literal
GET /somepath/somefile HTTP/1.1

request sent by the browser.

There are hundreds of examples of the correct use in other threads in this forum you can refer to.

They usually look something like

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /<some-RegEx-pattern>\ HTTP/