Hiding path that one domain gets redirected to

Using a single web hosting account to host multiple sites

Hiding path that one domain gets redirected to

Postby bregenspan » Thu May 24, 2007 10:25 am

To run two separate sites with separate domains on my hosting account, I am using an htaccess file at the root of the main site with:
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule ^(.*)$ /mysite/$1

This works great but I'm running into an issue where typing a subdirectory name without a trailing slash exposes the directory name of the redirect (which makes for an ugly, redundant URL). For example:

A query to http://www.mysite.com/charts/ leaves this in the address bar, but a query to http://www.mysite.com/charts gets redirected to http://www.mysite.com/mysite/charts/

Does anyone know if there's any way around this? Thanks in advance!
bregenspan
 
Posts: 1
Joined: Thu May 24, 2007 10:16 am

Postby richardk » Thu May 24, 2007 1:47 pm

This should fix it
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/mysite%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Domain to sub directory.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^(.*)$ /mysite/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 87 guests

cron