Best way to redirect a url (LAMP on debian)
I have the domains, let's say: mydomain.com, mydomain.net, mydomain.co etc. mydomain.com is my main website. What would be the best way to redirect the .net and .co domains to mydomain.com with as little interference as possible and without the user being interrupted. I do not want, for example, mydomain.net to serve the same content as mydomain.com but still show the .net domain in the URL bar, but I want it to actually redirect to the .com
I am running LAMP on debian.
Thanks
4 Replies
Good luck
ServerName mydomain.com
ServerAlias www.mydomain.com
ServerAlias mydomain.net
ServerAlias www.mydomain.net
RewriteEngine on
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://mydomain.com/$1 [L,R=301]
<virtualhost *:80="">ServerName mydomain.net
ServerAlias mydomain.co
RedirectMatch permanent ^(.*)$ http://mydomain.com$1</virtualhost>
<virtualhost *:80="">ServerName mydomain.com
# Complete configuration here...</virtualhost>
Would redirect all requests for mydomain.net and mydomain.co to mydomain.com
@sleddog:
Another method is to simply use Apache's RedirectMatch:
<virtualhost *:80="">ServerName mydomain.net ServerAlias mydomain.co RedirectMatch permanent ^(.*)$ http://mydomain.com$1</virtualhost> <virtualhost *:80="">ServerName mydomain.com # Complete configuration here...</virtualhost>
Would redirect all requests for mydomain.net and mydomain.co to mydomain.com
Thanks, I like that approach much better as I dont even need to have a separate directory structure for my extra domains, and my vhost file is much cleaner.