Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rewrite Rule Problem

Status
Not open for further replies.

cjhowland

Programmer
Apr 25, 2002
12
0
0
GB
I am trying to map a domain to a subdirectory of a hosting account using a rewrite rule in .htaccess. This works fine if just the domain name is entered, but if a subdirectory of the mapped domain is entered the location is found, but the location bar resolves to the file path of the main domain, unless a trailing '/' is keyed with the URL

For example :

" works fine
" works fine
" redirects to which is not the desired effect.

The .htaccess rewrite entries are as follows :

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^( [NC]
RewriteRule !^sites/mumps.biz /sites/mumps\.biz%{REQUEST_URI} [L]

I've tried putting a trailing slash in the last line, i.e
RewriteRule !^sites/mumps.biz /sites/mumps\.biz%/{REQUEST_URI} [L]

but this then results in redirecting to whereas it leaves in the location bar as I have it now.

I want to look to visitors like a fully independant domain, and not show in the location bar anything to do with the actual domain that the files reside on.

Any ideas?

Thanks
 
Thanks, that is exactly the problem. However, I can't work out from this document exactly what I need to do to resolve the issue. I tried adding the following to the top level .htaccess, as per the document :

RewriteBase /sites/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]

but then, although still serves correctly, gives a page not found.
 
I've searched the forum and found, with a bit of tweeking, that the following seems to work :

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.*) [L]
RewriteCond %{HTTP_HOST} ^( [NC]
RewriteRule !^sites/mumps.biz /sites/mumps\.biz%{REQUEST_URI} [L]

Hope that helps other people. The key seemed to be using the [L] option instead of [R] on the first RewriteRule. To be honest I don't know what the difference is, but it works on my site :

See which now leaves the URL unchanged in the location bar, and shows the same page as
I now have a domain running within a subdirectory of another domain but appearing to visitors as if it is a full hosted domain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top