PDA

View Full Version : .htaccess subdirectory issue



r2b2
11-12-2007, 03:21 AM
Ok, it's getting late and my brain is fried...

I've got an .htaccess file in place so that my main domain is served up from a subdirectory. Things work fine unless I'm requesting a directory and leave off the trailing slash.

What I want to happen is that if I request http://www.example.com/content it will end up requesting http://www.example.com/content/. However instead, it ends up requesting http://www.example.com/subdirectory/content/

Anyone know if there is a way around this or is it the base Apache config that's causing the problem?

I'm using the code supplied from the HostMonster helpdesk but I've put it below for ease of help - Note I have changed the relevant sections :D


# Hostmonster.com
# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.
RewriteEngine on

# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subfolder/

# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /subfolder/$1

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

r2b2
11-26-2007, 02:03 AM
Just bumping this thread in case anyone has a brainwave :D

Seb
11-26-2007, 01:52 PM
What about adding the red line? Not tested


# Hostmonster.com
# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.
RewriteEngine on

# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_URI} ^/(.+)!(/)$

# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /subfolder/$1

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

shadmego
11-26-2007, 11:02 PM
..:: Administrative Note ::..

Thread moved to Advanced Forum due to content.

r2b2
11-27-2007, 02:36 AM
Thanks for trying Seb but unfortunately that breaks it completely (i.e. you get page not found errors).

Back to the drawing board - maybe I'll check with the support guys. Maybe its just the way it is with the Hostmonster Apache setup...

Seb
11-27-2007, 03:40 AM
Next try ;)

RewriteCond %{REQUEST_URI} !^/(\w+)$

I actually tested this on my domain and I cannot reproduce that behavior. It works (as you want it too) without changing anything.

r2b2
11-27-2007, 03:47 AM
Well it isn't giving me 404s but its not doing what I want.

I wonder if another rewrite rule is interfering with the rest.... I'll try going back to basics and see what happens.

Thanks for your help so far!

sjlplat
11-27-2007, 05:55 AM
I got this from the Bluehost forums. No clue if it works or not:


RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net
RewriteCond %{REQUEST_URI} !^/subdirectory
Rewriterule ^(.*)$ /maindomain/$1 [L]