Discussion:
trying to redirect an entire domain *with* exceptions
(too old to reply)
Peter
2012-08-08 13:03:40 UTC
Permalink
Hi,

in .htaccess

I would like to do the following (which works btw) :

# RewriteCond %{HTTP_HOST} ^(.*)?olddomain.net [NC]
# RewriteCond %{REQUEST_URI} !^/page1\.php$ [NC]
# RewriteCond %{REQUEST_URI} !^/page2\.php$ [NC]
# RewriteRule (.*) http://www.newdomain.com/$1 [R=307,L]

BUT

- I would also add the root to the exception (www.olddomain.com as is still works)

- And I would also like to add ALL *.xml files to the exception filter, no matter where these xml files are located (any directory deep)

Could anybody advice on what to lines to add to this redirection ?

Thanks
D. Stussy
2012-08-08 19:02:06 UTC
Permalink
"Peter" wrote in message news:3e468780-b9c8-4ec9-a9a6-***@googlegroups.com...
in .htaccess

I would like to do the following (which works btw) :

# RewriteCond %{HTTP_HOST} ^(.*)?olddomain.net [NC]
# RewriteCond %{REQUEST_URI} !^/page1\.php$ [NC]
# RewriteCond %{REQUEST_URI} !^/page2\.php$ [NC]
# RewriteRule (.*) http://www.newdomain.com/$1 [R=307,L]

BUT

- I would also add the root to the exception (www.olddomain.com as is still
works)

- And I would also like to add ALL *.xml files to the exception filter, no
matter where these xml files are located (any directory deep)

Could anybody advice on what to lines to add to this redirection ?
==========================
Comments:

1) RewriteCond %{HTTP_HOST} ^(.*)?olddomain.net [NC]
should be
RewriteCond %{HTTP_HOST} ^(.*\.)?olddomain.net$ [NC]

2) RewriteRule (.*) http://www.newdomain.com/$1 [R=307,L]
should be
RewriteRule (.*) http://%1newdomain.com$1 [R=307,L]
Maybe you want 301 instead of 307 if this is a permanent change.

3) Maybe you want the conditions regarding REQUEST_URI to be BEFORE the
condition checking the HTTP_HOST for efficency because as this is in an
".htaccess" file, you already KNOW that the hostname should match (else the
virtual host mapping would not have reached that directory unless it's the
first virtual host or no VH's defined in the main configuration).

Notes:
1) Makes certain that anything before "olddomain" is a hostname and not some
other domain with the substring.

2) Rewrites to the same hostname under the domain. Also, "(.*)" already
contains a leading slash, so drop it.


I usually don't do rewrites in .htaccess but only in my main configuration, so
there's something I may have missed.
Peter
2012-08-08 20:24:25 UTC
Permalink
Post by D. Stussy
1) RewriteCond %{HTTP_HOST} ^(.*)?olddomain.net [NC]
should be
RewriteCond %{HTTP_HOST} ^(.*\.)?olddomain.net$ [NC]
2) RewriteRule (.*) http://www.newdomain.com/$1 [R=307,L]
should be
RewriteRule (.*) http://%1newdomain.com$1 [R=307,L]
Maybe you want 301 instead of 307 if this is a permanent change.
3) Maybe you want the conditions regarding REQUEST_URI to be BEFORE the
condition checking the HTTP_HOST for efficency because as this is in an
".htaccess" file, you already KNOW that the hostname should match (else the
virtual host mapping would not have reached that directory unless it's the
first virtual host or no VH's defined in the main configuration).
1) Makes certain that anything before "olddomain" is a hostname and not some
other domain with the substring.
2) Rewrites to the same hostname under the domain. Also, "(.*)" already
contains a leading slash, so drop it.
Thanks for these tips !! Will implement tomorrow.

Regarding the OP, could you answer the two questions ?

1. How do I filter the root, as in the root should not redirect
2. How to I filter *all* .xml files, no matter how deep in the folder structure they are. As in .xml files should not redirect, but stay accessible under the old domain.

Thx
D. Stussy
2012-08-11 00:25:48 UTC
Permalink
"Peter" wrote in message news:9c4d2768-c6c2-4841-b552-***@googlegroups.com...
Thanks for these tips !! Will implement tomorrow.

Regarding the OP, could you answer the two questions ?

1. How do I filter the root, as in the root should not redirect
2. How to I filter *all* .xml files, no matter how deep in the folder
structure they are. As in .xml files should not redirect, but stay accessible
under the old domain.
===================

1) Change to:

RewriteRule /(.+) http://%1newdomain.com$1 [R=307,L]

2) I'm not certain that can be done with a single .htaccess file. Try:

RewriteCond %{REQUEST_URI} [^/]+\.xml$ [NC]

However, you may have to repeat that in every .htaccess file under the desired
point.

Continue reading on narkive:
Loading...