www.domain.com/directory => www.directory.com

Using a single web hosting account to host multiple sites

Postby DecisionsIN » Thu Mar 22, 2007 2:28 pm

That causes www.domain.com to display a page cannot be found error. What I have thus far is:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# Exclude these root directories
RewriteCond %{SCRIPT_FILENAME} !ROOT FOLDER TO EXCLUDE$
RewriteCond %{SCRIPT_FILENAME} !ROOT FOLDER TO EXCLUDE$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^folder(/.*)?$ /folder%{REQUEST_URI} [QSA,L]


This seems to work really well. I have to update my links, but that is something I should probably do any way. The only thing I'd like to solve now is to force a redirect of:

www.domain.com/aSpecificFolder >> www.domain.com

I only want to force this redirect for one folder though. Not sure if this is possible.

Thanks again for all your help!
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Thu Mar 22, 2007 2:33 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^folder(/(.*))?$ http://www.domain.com/$2 [R=301,L]

RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^(folders|to|ignore)(/.*)$ /folder%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DecisionsIN » Mon Mar 26, 2007 12:48 pm

For the most part the code below is working, but it's now breaking my ErrorDocument command. Here is the code I'm currently using:

Code: Select all
Options +FollowSymLinks

ErrorDocument 401 /error_401.jsp
ErrorDocument 403 /error_403.jsp
ErrorDocument 404 /error_404.jsp
ErrorDocument 500 /error_500.jsp

RewriteEngine On

#RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteRule ^folder(/(profile\.jsp|account\.jsp))?$ http://www.domain.com/$2 [R=301,L]

# Force www.
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

# Exclude these root directories
RewriteCond %{SCRIPT_FILENAME} !FOLDER TO IGNORE$
RewriteCond %{SCRIPT_FILENAME} !FOLDER2 TO IGNORE$
RewriteCond %{SCRIPT_FILENAME} !FOLDER3 TO IGNORE$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]

# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^folder(/.*)?$ /folder%{REQUEST_URI} [QSA,L]

Redirect 301 /index.jsp http://www.domain.com/folder/


Before I started using mod_redirect ErrorDocument worked fine. Now, it just spits out a normal browser error page, not the custom error page. If I uncomment out the code below ErrorDocument works again:

Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^folder(/.*)?$ /folder%{REQUEST_URI} [QSA,L]


Do you have any idea why that code might prevent ErrorDocument from working?

I really appreciate all your help.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Mon Mar 26, 2007 1:07 pm

It's sending all requests that don't exist to /folder. Try putting the error document line in a .htaccess file in there.

Or try
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -f
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -d
RewriteRule !^folder(/.*)?$ /folder%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DecisionsIN » Mon Mar 26, 2007 5:13 pm

The two lines below break the relative paths so the site doesn't display properly:

Code: Select all
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -f
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -d


If I remove them the site loads properly. Is there something I need to add?

Also, when I put ErrorDocument into the /folder .htaccess file I get the same result. It just displays the normal browser error page. Not sure what is going on here.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Tue Mar 27, 2007 11:22 am

The two lines below break the relative paths so the site doesn't display properly

What relative paths? In links and image sources, etc.?

Do the files/directories actually exist in /folder? How many are there?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DecisionsIN » Wed Apr 04, 2007 8:46 am

Sorry for the delayed response. I've been out of town.

When I include the code below it breaks all the relative paths--such as SSI and image paths--of files that are stored in /folder. For example, any relative paths to /images, where images reside in /folder don't work. I hope that make sense.

Code: Select all
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteRule ^folder(/(file\.jsp|file2\.jsp))?$ http://www.domain.com/$2 [R=301,L]


We have about ten active folders and thirty or so files that reside inside of /folder.

BTW, even when I move ErrorDocument to the /folder .htaccess file it still doesn't work.

Thanks again for all your help.
Last edited by DecisionsIN on Wed Apr 04, 2007 8:52 am, edited 1 time in total.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Wed Apr 04, 2007 8:51 am

I still don't understand the problem. Please give examples with full paths.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

index files in excluded folders

Postby germanicus » Sun Apr 22, 2007 11:53 pm

Hi!

If found this thread hugely helpful. Thanks!
One little thing remains though.

The functionality of automatically recognising index files (index.htm, index.php, etc) has been lost in all of the excluded folders (folders|to|ignore).

I'm sure there's a simple fix for that.
Thanks for your help.
germanicus
 
Posts: 4
Joined: Sun Apr 22, 2007 11:44 pm

Postby richardk » Mon Apr 23, 2007 9:55 am

Post the mod_rewrite you are using.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

PreviousNext

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 8 guests

cron