Hi, I wrote some regex for the domain rewrite part in .htaccess of modx evolution 1.0.4.
Often I have a developer URL and later a .ch and a .com domain, but after going online, my clients sometimes still uses the dev url which can lead to caching issues or other problems. The following regex should cover these situations:
http://domain.com.foo.bar.my-host.net (developer URL)
http://domain.com
http://domain.ch
http://www.domain.com
http://www.domain.ch
And be able to redirect the domain to one of any of the last 4.
I am not an expert with regex patterns, but got 4 solutions working that I’d like to share and get feedback here. If you find a better solution please let me know. I used
http://regexpal.com/ and
http://gskinner.com/RegExr/
# go to www.domain.ch
#RewriteCond %{HTTP_HOST} !^www\.(domain\.(ch|(?=ch\.))) [NC]
#RewriteRule (.*) http://www.domain.ch/$1 [R=301,L]
# go to domain.ch
#RewriteCond %{HTTP_HOST} (www\.)|(domain\.((?!ch)|(?=ch\.))) [NC]
#RewriteRule (.*) http://domain.ch/$1 [R=301,L]
# go to www.domain.com
#RewriteCond %{HTTP_HOST} !^www\.(domain\.(com|(?=com\.))) [NC]
#RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# go to domain.com
RewriteCond %{HTTP_HOST} (www\.)|(domain\.((?!com)|(?=com\.))) [NC]
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Any feedback appreciated!
I don’t think it’s good enough or tested enough yet, to propose to include in modx, but hopefully with your feedback will. Use this code at your own risk!
(I’ve signed the CLA but not sure it ever arrived yet) so this solution is totally free code under public domain!
Cheers
eni