Forum Moderators: phranque
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
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]
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]
Our forum charter [webmasterworld.com] contains links to several useful resources for mod_rewrite and regular expressions.
Jim
[edit] Added loop prevention [/edit]
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
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]