Forum Moderators: phranque

Message Too Old, No Replies

Two domains same IP. redirect question

forward domain name to a specific URL at my main site

         

giorgos

7:06 pm on Jan 28, 2005 (gmt 0)

10+ Year Member



I need to forward my newly registered domain name to a specific URL at my main site. Both domains pointing to the same IP where my web server runs.
When requests come in from [mynewdomain.com...] should go to [mynewdomain.com...]
When requests come in from [mydomain.com...] should also go to [mynewdomain.com...]

My two domains are:
[mydomain.com...] points to the "index.php" of the site.
[mynewdomain.com...] points to same page as the above domain but I want it to point to [mynewdomain.com...]

If I use apache virtual hosts as follows but it gives me a “page not found” for the above url
<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot C:\AppServ\www
ServerName mydomain.com
ServerAlias mydomain.com *.mydomain.com
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@mynewdomain.com
DocumentRoot C:\AppServ\www\modules\gallery
ServerName mynewdomain.com
ServerAlias mynewdomain.com *.mynewdomain.com
RedirectPermanent / [mynewdomain.com...]
ErrorLog logs/mynewdomain_log_error
CustomLog logs/mynewdomain_log_common common
</VirtualHost>

I also tried a RewriteRule within my htaccess or virtual hosts container but it didn’t’ work as I’m really a newbie in apache

RewriteEngine On
RewriteCond %{HTTP_HOST}!^mynewdomain\.com [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^/(.*) [mynewdomain.com...] [L,R]

I appreciate any help

Thanks
Giorgos

jdMorgan

7:30 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Giorgos,

Welcome to WebmasterWorld!

It looks as though you've copied code from another thread without fully understanding what it does. A likely cause for the trouble you are having is that the "!" character means NOT. So, your code will only redirect if the requested domain is NOT mynewdomain.com.

If you want an external redirect, I'd suggest:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mynewdomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/modules\.php$
RewriteCond %[QUERY_STRING] !^op=modload&name=Gallery&file=index/
RewriteRule ^/(.*) http://www.mynewdomain.com/modules.php?op=modload&name=Gallery&file=index/$1 [R=301,L]

To use an internal rewrite, use:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mynewdomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/modules\.php$
RewriteCond %[QUERY_STRING] !^op=modload&name=Gallery&file=index/
RewriteRule ^/(.*) /modules.php?op=modload&name=Gallery&file=index/$1 [L]

An internal rewrite simply substitutes the new filepath for the old, while an external redirect sends a rsponse to the client browser, telling it to re-request the page from the new URL. As such, it is visible to the user, and much less efficient.

Our forum charter [webmasterworld.com] contains links to several useful resources for mod_rewrite and regular expressions.

Jim

[edit] Added loop prevention [/edit]

giorgos

7:22 am on Jan 29, 2005 (gmt 0)

10+ Year Member


Jim,

Thank you very much for your fast reply. Indeed I copied the code from another thread and tried out.

I also tried the code you mentioned by making an htaccess file at my web root directory but nothing is changed. When I type http://www.mynewdomain.com it doesn't redirect to http://www.mynewdomain.com/modules.php?op=modload&name=Gallery&file=index but remains at http://www.mynewdomain.com.
I tried this with virtual hosts and without at my httpd.conf virtual hosts section.

Any idea what is going wrong?
Thanks,
Giorgos

giorgos

3:21 pm on Jan 29, 2005 (gmt 0)

10+ Year Member


Noticed that if I use following code the redirect works.

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

When I change the url at the rewriterule is doing nothing (looks like looping)

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/modules.php?op=modload&name=Gallery&file=index$1 [R=301,L]