PDA

View Full Version : URL Redirect Question???



PDidee
April 19th, 2007, 09:09 AM
I have an FTP that would like to host two web sites on in two different directories. I have two domain names that point to the same server.
QUESTION: Is it possible to redirect a user to a specific directory they type into their browser?
ie. If user types www.site1.com they are directed to www.mainsite.com/site1/index.html
and if user types www.site2.com they are directed to www.mainsite.com/site2/index.html

:q:

foodpk
April 19th, 2007, 09:31 AM
Hi! I assume your webserver is Apache. If so then try this. In the root folder of your webserver, place a .htaccess file. That file should contain the following:


RewriteCond %{HTTP_HOST} site1.com
RewriteRule (.*) /site1folder/$1 [R=301,L]
RewriteCond %{HTTP_HOST} site2.com
RewriteRule (.*) /site2folder/$1 [R=301,L]

The above should redirect anything that comes through to site1.com to the folder /site1folder/ and the same for site2.com
Anyway, the above should work, setting up proper URL redirection is usually kind of tricky and always contains some trial and error.

Another way to do that is by setting up virtual hosts in your httpd.conf file. You can try placing the code below at the end of your httpd.conf file but a lot of it depends from server to server so I can't really say if it will work or not.


NameVirtualHost *
<VirtualHost *>
ServerName www.site1.com
DocumentRoot /www/site1folder
ServerAlias site1.com *.site1.com
</VirtualHost>
<VirtualHost *>
ServerName www.site2.com
DocumentRoot /www/site2folder
ServerAlias site1.com *.site1.com
</VirtualHost>

PDidee
April 19th, 2007, 11:13 AM
Thanks for the quick response. I gave this a shot but it's not working sadly. :(

puppy
April 19th, 2007, 01:16 PM
things like
RewriteRule (.*) /folder/$1 do not work on my host for some unknown reason :( what I do instead is [edit: wtf it does not work too]

you might also want to add
RewriteEngine on

puppy
April 19th, 2007, 01:29 PM
saaay, isn't your host godaddy, per chance?
rewriterule ^/1.+$ /folder$0 [L]correctly finds blah.com/11.html under /folder/11.html, but
rewriterule ^/.+$ /folder$0 [L]does not. maybe they are blocking mass redirects...

puppy
April 19th, 2007, 01:45 PM
finally fixed this #@$%

rewriteengine on
rewritecond %{http_host} ^(www.)?domain.com$ [nc]
rewriterule ^/$ /folder/ [L]
rewriterule ^/[/]+$ /folder/ [L]
rewriterule ^/[^/]+$ /folder$0 [L]

oh noes. it fails with several slashes /blah/doh :(

PDidee
April 19th, 2007, 03:04 PM
Yeah I have godaddy.com Currently I have two domain names ointing to the same FTP. This is the code for the .htaccess file:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} mydomainname1.com
RewriteRule (.*) /site1/$1 [r=301,L]
RewriteCond %{HTTP_HOST} mydomainname2.net
RewriteRule (.*) /site2/$1 [r=301,L]

But it didn't work :( And suggestions would be much appriciated.

Thanks.

foodpk
April 19th, 2007, 03:08 PM
Yeah, that should be about right, sorry, I forgot to add rewriteegnine on and +FollowSymlinks is good to set, but anyway, when you say it doesn't work, what happens? Do you get an internal server error (500)?? Or it just doesn't display the site, or what?

PDidee
April 19th, 2007, 04:48 PM
It goes to the same index page no matter what. No error message.

OKAY HERE's the error I'm getting now:
Too many redirects occurred trying to open “http://solitaryearth.com/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/site1/html/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.

And I can't access the file now. :(

PDidee
April 20th, 2007, 09:41 AM
Well I upgraded my package to avoid the headache and it's much easier now. For $4 a month extra I get more space and functionality and unlimited URL points.

puppy
April 20th, 2007, 10:07 AM
URL points?

PDidee
April 20th, 2007, 05:33 PM
URL points?

yep! I can point an unlimited number of domain names to different directories on my ftp.