Jump to content

htaccess help


Petter Enge

Recommended Posts

Hello

Any expert on htaccess out there ?

I have 2 domains. 

Domain 1 has a webhotel.

Domain 2 has files installed under http://domain1.com/domain2

Both domain use the IP address for the same webhotel.

I want to let the htaccess file for domain 1 include a forward so that when people type http://domain2.com/ it will be routed to http://domain1.com/domain2

And also so that the browsers window shows http://domain2.com

Is this possible ?

 

Link to comment
Share on other sites

  • 1 month later...

Something like this? Source

RewriteEngine on
RewriteBase /
# capture the original request so you never have trouble with (un)escaping
RewriteCond %{THE_REQUEST} \S+\s+(\S*)
RewriteRule ^ - [E=REQ:%1]
# ensure the domain goes to the required dir
#  get domain
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)
RewriteRule ^ - [E=DOM:%1]
#  explicitly set dir per host
RewriteCond %{ENV:DOM} =sub.domain1.com [NC]
RewriteRule !^sub/ sub%{ENV:REQ} [NE,DPI,L]
RewriteCond %{ENV:DOM} =domain2.com [NC]
RewriteRule !^d2/ d2%{ENV:REQ} [NE,DPI,L]

# allow domain1.com to proceed to root (any other rules go below)
# rules must still exclude subdirectories for other domains, e.g.:
RewriteRule ^(?!sub/|d2/)([^/]+)/([^/.]+)$ foo.php?bar=$1&baz=$2 [NE,B,L,DPI]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(?:sub/|d2/|index\.php$) index.php [L,DPI]

# after all other rules, emulate DirectorySlash so that Apache does not naively insert hidden directory into public URL
DirectorySlash off
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (?>.*)(?<!/) %{ENV:REQ}/ [L,DPI,R]

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...