Silent redirect from base directory

Using a single web hosting account to host multiple sites

Silent redirect from base directory

Postby caspianxi » Fri Jul 14, 2006 6:09 pm

I've got two domain names (using one hosting account): first.com and second.com. first.com is the "main" domain, and second.com is a addon domain.

Inside of my root directory (/www) is two folders: first_content and second_content.

When the user visits http://www.first.com, I want the user to be silently redirected to http://www.first.com/first_content/. When the user visits http://www.second.com, they're redirected to http://www.first.com/second_content.

Here's the .htaccess file I'm using (I can't figure out how to do it for second_content):
Code: Select all
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(.*)$ /first_content/ [NC,L]


For some reason, I if I place this .htaccess file inside of first.com/test, it redirects from first.com/first_contents. But if I move the .htaccess file to the root directory, I get a 500 server error.

I'd greatly appreciate anyone who can help me.

Thanks
caspianxi
 
Posts: 3
Joined: Fri Jul 14, 2006 5:29 pm

Postby richardk » Sat Jul 15, 2006 4:29 am

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# match the domain first.com or second.com, optional www.
RewriteCond %{HTTP_HOST} ^(www\.)?(first|second)\.com$ [NC]
# as long as it's not a request for /*_content/, rewrite it
RewriteRule !^[a-zA-Z0-9\-]+_content(/.*)?$ /%2_content%{REQUEST_URI} [QSA,L]


Edit 1: Added "_content" to RewriteRule (after %2).
Edit 2: Removed ^ from [] in RewriteRule.
Last edited by richardk on Mon Jul 17, 2006 4:15 pm, edited 3 times in total.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby caspianxi » Mon Jul 17, 2006 3:58 pm

Thanks, richardk! It works great :D

One small thing... When I go to http://www.mysite.com/directory/, it pulls up that directory's index page. But when I go to http://www.mysite.com/directory (notice the missing tailing slash), it redirects to http://mysite.com/_content/directory/.

I tried adding this line to the .htaccess file:

redirect /_content/ http://www.mysite.com/


But then, it gets into an eternal loop of redirecting. Is there any way I can manually redirect http://www.mysite.com/directory to http://www.mysite.com/directory/?

Well, this isn't that big of a deal if I can't get it working. The big thing is that my visitors are automatically redirected to the _content directory :)

Thanks again for your help. :D :D[/quote]
caspianxi
 
Posts: 3
Joined: Fri Jul 14, 2006 5:29 pm

Postby richardk » Tue Jul 18, 2006 11:15 am

Try this:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# add missing trailing slash to directories
RewriteCond %{HTTP_HOST} ^(www\.)?(first|second)\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2_content%{REQUEST_URI}/ -d
RewriteRule !^(.+/)?$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?(first|second)\.com$ [NC]
RewriteRule !^[a-zA-Z0-9\-]+_content(/.*)?$ /%2_content%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby caspianxi » Wed Jul 19, 2006 7:10 am

Sweet... it works!!

Thanks, richardk. You're a genious :D
caspianxi
 
Posts: 3
Joined: Fri Jul 14, 2006 5:29 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 90 guests

cron