Reputation: 736
I've registered 3 domains, all for the same site. I've done this to catch people who can't remember the right URL. So I've got:
The hosting is under #1, with #2 and #3 as parked domains.
# BEGIN WordPress
IfModule mod_rewrite.c> # deliberate missing open tag to show this line here
RewriteEngine On
RewriteBase / # from Wordpress
RewriteCond %{REQUEST_FILENAME} !-f # from Wordpress
RewriteCond %{REQUEST_FILENAME} !-d # from Wordpress
RewriteRule . /index.php [L] # from Wordpress
# Point all domains to .org.au
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.au [NC]
RewriteRule ^(.*)$ http://domain.org.au/$1 [R=301,L]
# RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org [NC]
# RewriteRule ^(.*)$ http://domain.org.au/$1 [R=301,L]
/IfModule> # deliberate missing close tag to show this line here
# END WordPress
My first redirect works fine, but when I add the .org -> .org.au the browser chokes and says I have to many redirects. Which is possible, this is my first foray into .htaccess. So - what am I doing wrong?
Upvotes: 1
Views: 64
Reputation: 38309
Your second RewriteCond
only checks whether the hostname begins with (www.)domain.org
, so it will still match after a redirect to domain.org.au
. This will cause an infinite number of redirects, causing your browser to give up after a certain number of tries.
What you really need is to match (www.)domain.org(END)
instead. The dollar sign $
represents end-of-string in regular expressions, like so:
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.au$ [NC]
RewriteRule ^(.*)$ http://domain.org.au/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org$ [NC]
RewriteRule ^(.*)$ http://domain.org.au/$1 [R=301,L]
The ^(www\.)?domain\.com\.au$
expression works like this:
^
= beginning of string(www\.)
= "www." as a group?
= the previous group either one or zero timesdomain\.com\.au
= domain.com.au (dots normally mean "any character", but not when they are preceded by backslash)$
= end of stringSo, the entire expression means:
exactly "domain.com.au" and no other characters, optionally preceded by "www."
Upvotes: 2