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

Using a single web hosting account to host multiple sites

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

Postby Ruben » Sat Feb 10, 2007 4:22 pm

Is this possible if 'www.directory.com' domain name is pointing to the www.domain.com servers?

www.domain.com/directory => www.directory.com
Ruben
 
Posts: 4
Joined: Thu Jan 18, 2007 10:56 am

Postby richardk » Sun Feb 11, 2007 2:57 pm

You need DNS for the domain, and it needs to point to domain.com's document root.

Then in a .htaccess file in domain.com's document root:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(directory)\.com$ [NC]
RewriteRule ^(.*)$ /%2/$1 [QSA,L]


If "directory" changes, replace it with "[-a-z]+".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

www.domain.com/directory => www.directory.com - Not worki

Postby DecisionsIN » Tue Mar 20, 2007 2:17 pm

Hi! New to this forum. Great service and information.

I am trying to do something similar on my site but something is not working right. I am trying to make the folder "www.domain.com/folder" show up as www.domain.com. The code I tried using WAS as follows:

Code: Select all
#RewriteEngine On

#RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
#RewriteRule !^folder(/.*)?$ /folder%{REQUEST_URI} [QSA,L]


This worked, but the pathing was off. Everything that is stored in the /folder directory rendered fine. But I also have files in the root that need to load, such as scripts and some images. Poor design I know.

I am wondering if there is code to do the following:

1) I need www.domain.com/folderto show up www.domain.com in the browser.

2) I need all the folders and files in the root (e.g. domain.com/album, domain.com/_scripts, etc.) to still load correctly.

3) I'd also like to force non-www to be www.

Any assistance you can provide will be greatly appreciated!

Thanks!
Last edited by DecisionsIN on Thu Mar 22, 2007 9:52 am, edited 1 time in total.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Tue Mar 20, 2007 2:40 pm

This should do it
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?decisionsin\.com$ [NC]
# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
# Ignore real directories (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /inspace/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DecisionsIN » Tue Mar 20, 2007 3:02 pm

richardk wrote:This should do it
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.
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]
# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
# Ignore real directories (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [QSA,L]


Wow, thanks for the amazingly quick reply. Here is the result:

The redirect from non-www to www seemed to worked correctly, but the rest didn't produce the desired result. Here is what happened:

- When I loaded www.domain.com the splash loaded correctly. The splash page is www.domain.com/index.jsp. I no longer want to use this splash page, which is why I want to load the content in /folder.

- When I go to www.domain.com/folder I get the following error:

404 Not Found
/folder/folder/ was not found on this server.


- I would prefer that www.domain.com load www.domain.com/folder, but for page rank and esthetic reasons I'd like to have the URL in the browser display as www.domain.com.

Thanks again for your help and quick response!
Last edited by DecisionsIN on Thu Mar 22, 2007 9:53 am, edited 1 time in total.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Tue Mar 20, 2007 3:30 pm

Ah, replace ".*" in the last rule, with ".+".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DecisionsIN » Tue Mar 20, 2007 4:35 pm

richardk wrote:Ah, replace ".*" in the last rule, with ".+".


Thanks again for the quick reponse. Unfortunately, seems to be the same result. To make this easier I went ahead and left the code in the .htaccess file. The site is down but at least this way you can see what is going on. Check out http://www.domain.com and http://www.domain.com/folder. I can't leave the site down for too long, so if the site happens to work then I removed the code.

Here is the code I used:

Code: Select all
# Force www.
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]
# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
# Ignore real directories (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /folder/$1 [QSA,L]
Last edited by DecisionsIN on Thu Mar 22, 2007 9:54 am, edited 1 time in total.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby DecisionsIN » Tue Mar 20, 2007 5:29 pm

domain wrote:
richardk wrote:Ah, replace ".*" in the last rule, with ".+".


Thanks again for the quick reponse. Unfortunately, seems to be the same result. To make this easier I went ahead and left the code in the .htaccess file. The site is down but at least this way you can see what is going on. Check out http://www.domain.com and http://www.domain.com/folder. I can't leave the site down for too long, so if the site happens to work then I removed the code.

Here is the code I used:

Code: Select all
# Force www.
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]
# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
# Ignore real directories (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /folder/$1 [QSA,L]


I had to go revert back, so the site is working again. I was experiencing the same problems I outlined in my initial response.
Last edited by DecisionsIN on Thu Mar 22, 2007 9:55 am, edited 1 time in total.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby DecisionsIN » Tue Mar 20, 2007 6:11 pm

Okay, I almost got this working my using the following code:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.
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]
# Ignore real files (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^folder(/.*)?$ /folder%{REQUEST_URI} [QSA,L]


As you can see I removed the following line:

Code: Select all
# Ignore real directories (in your document root).
RewriteCond %{SCRIPT_FILENAME} !-d


I'm not sure why this worked.

I only have a few issues left so solve.

- First, if you click on any link, such as "Home" you are taken to http://www.domain.com/folder/, not http://www.domain.com/. Do you know if there is any way to prevent /folder from being displayed in the browser when clicking links?

- On a similar note, if I type in http://www.domain.com/folder/ it still displays as such in the browser. Is there a way to make it show up as http://www.domain.com/ in the browser?

- Lastly, our forum link is no longer working. The link to our forum is, http://www.domain.com/forum. Is there a way to exclude/include certain directories in the root so they continue to work?

Sorry for the long winded response. Thank you again.
DecisionsIN
 
Posts: 15
Joined: Tue Mar 20, 2007 1:33 pm

Postby richardk » Thu Mar 22, 2007 1:38 pm

Try
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
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 96 guests

cron