Rewrite two site to one

Using a single web hosting account to host multiple sites

Rewrite two site to one

Postby Weeelo » Thu Jul 16, 2009 1:10 pm

Hi,

I have the following:

public_html/site1
public_html/site2
public_html/forum

What I want is the following:

www.site1.com/forum -> public_html/forum
www.site2.com/forum -> public_html/forum

If I place the following in my public_html it gives an Internal Server Error:

RewriteEngine On
RewriteBase /
RewriteRule site1/forum/ forum/
RewriteRule site2/forum/ forum/

How can I do this correct?
Weeelo
 
Posts: 8
Joined: Thu Jul 16, 2009 10:30 am

Postby richardk » Thu Jul 16, 2009 2:13 pm

How did you get site1.com to go to public_html/site1?
Can you create symbolic links? That would probably be the best option.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Weeelo » Thu Jul 16, 2009 2:19 pm

They are redirected through the adminsystem, cPanel, on my host.

I don't know if I can create symbolic links. Is there a way I can check that?
Weeelo
 
Posts: 8
Joined: Thu Jul 16, 2009 10:30 am

Postby richardk » Thu Jul 16, 2009 3:29 pm

They are redirected through the adminsystem, cPanel, on my host.

Do you get to choose the directory? If you send them both to public_html/, you can use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/forum(/.*)?$
RewriteCond %{HTTP_HOST}/site1 ^(www\.)?site1\.com(/site1)$ [NC,OR]
RewriteCond %{HTTP_HOST}/site2 ^(www\.)?site2\.com(/site1)$ [NC]
RewriteCond %{DOCUMENT_ROOT}%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/forum(/.*)?$
RewriteCond %{HTTP_HOST}/site1 ^(www\.)?site1\.com(/site1)$ [NC,OR]
RewriteCond %{HTTP_HOST}/site2 ^(www\.)?site1\.com(/site2)$ [NC]
RewriteRule .* %2%{REQUEST_URI}/ [QSA,L]

but this may cause problems as the DOCUMENT_ROOT variable will be .../public_html/ not .../public_html/site1. A symbolic link would be better.

I don't know if I can create symbolic links. Is there a way I can check that?

I think you will need to ask your host.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Weeelo » Wed Aug 05, 2009 3:00 am

Sorry for the late reply. Should that .htaccess file be placed in public_html?

And the second last line should be:

RewriteCond %{HTTP_HOST}/site2 ^(www\.)?site2\.com(/site2)$ [NC]

Right?
Weeelo
 
Posts: 8
Joined: Thu Jul 16, 2009 10:30 am

Postby richardk » Wed Aug 05, 2009 3:29 pm

Should that .htaccess file be placed in public_html?

Yes. And site1.com and site2.com would need to go to public_html/ as well, not their sub directories.

And the second last line should be:

RewriteCond %{HTTP_HOST}/site2 ^(www\.)?site2\.com(/site2)$ [NC]

Yes.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Weeelo » Fri Aug 07, 2009 7:35 am

Ok, I'm just trying with one of my sites now, as the other one is online.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/forum(/.*)?$
RewriteCond %{HTTP_HOST}/fooz.dk ^(www\.)?fooz\.dk(/fooz.dk)$ [NC]
RewriteCond %{DOCUMENT_ROOT}%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/forum(/.*)?$
RewriteCond %{HTTP_HOST}/fooz.dk ^(www\.)?fooz\.dk(/fooz.dk)$ [NC]
RewriteRule .* %2%{REQUEST_URI}/ [QSA,L]


This is my .htaccess

But I get a 404 on both fooz.dk and fooz.dk/forum.
Weeelo
 
Posts: 8
Joined: Thu Jul 16, 2009 10:30 am

Postby richardk » Fri Aug 07, 2009 1:59 pm

Does this mod_rewrite test work?
If you remove the mod_rewrite and go to fooz.dk/forum do you see public_html/fooz.dk/forum or public_html/forum?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Weeelo » Sat Aug 08, 2009 2:04 am

I get this 404 on fooz.dk:

The requested URL /fooz.dk// was not found on this server.

If I go to fooz.dk/forum it shows public_html/fooz.dk/forum
Weeelo
 
Posts: 8
Joined: Thu Jul 16, 2009 10:30 am

Postby richardk » Wed Aug 12, 2009 10:40 am

Does this mod_rewrite test work?

I meant to link that to http://forum.modrewrite.com/viewtopic.php?p=10708#10708.

I get this 404 on fooz.dk:

The requested URL /fooz.dk// was not found on this server.

If I go to fooz.dk/forum it shows public_html/fooz.dk/forum

If this is without the mod_rewrite, then you haven't set fook.dk to go to public_html/ not public_html/fooz.dk/. You need to chnage fook.dk's document root to public_html/.

Do you have a domain that goes to public_html/?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron