Log in

View Full Version : .htaccess domain-level mod_rewrite appends change in visible URL



djr33
03-01-2011, 07:56 PM
I switched to a host for several of my domains that requires a "main" domain.
I don't have access to anything in the server configuration that lets me change that.

What I want is to host multiple sites, and have none of them located in the root folder.

In other words, I want the root folder to contain (in addition to several configuration files) /mydomain1.com/, /mydomain2.com/, etc.

This works fine except for that main domain that is supposed to be located in the root.

In order to work around this, I'm using mod_rewrite via .htaccess.

Here's my .htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ci-pro.com
RewriteCond %{REQUEST_URI} !^/ci-pro.com
RewriteRule ^(.*)$ ci-pro.com%{REQUEST_URI}

Here's the site:
http://ci-pro.com


Everything works well, except for one thing: the extra "ci-pro.com/" is appended to the URL when I visit a link. Load the page then click one of the links in the header-- it doubles the domain name (one for the domain, another for the subdirectory).

This is really annoying and I can't find any way around it or any information about this. I thought that mod_rewrite was supposed to be completely silent...

djr33
03-06-2011, 06:58 AM
An update and partial solution:

I missed that my links had no trailing slashes:
/mydir
instead of:
/mydir/

By adding the slashes, it made everything work.

In other words, the trailing slash is required by the server and the rewrite is converted to a redirect if it has no trailing slash (and it's a directory, not a file).

This doesn't exactly solve the original problem, but by adding a trailing slash to every link on my site now the error no longer appears. It's at least a solid temporary solution.


Now I wonder if there's any way to disable this requirement for a trailing slash...