Search

Sup peeps!

I'm putting a site together which has a few legacy domains purchased from previous ventures and they wish for the domains to be redirected to the master domains. these domains don't have any legacy content but I'm looking for the best approach using .htaccess to issue a 301 redirect for all the domains pointed at the VPS so it serves the one main domain all the content.

I've taken some htaccess code from a previous post and am wanting some advice on best approach baring in mind the symphony htaccess file already in place.. here's what I have so far:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

### GLOBAL REWRITE
RewriteCond %{HTTP_HOST} !^(www.)?domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,NC,L]
</IfModule>

I'm no htaccess guru but does the above rule look for any domain that is NOT www.domain.com and redirect it to domain.com.

Thanks in advance.

To be honest you'd be better doing this at the DNS level. Can you configure the DNS with the host to point to the new domain?

will the DNS issue correct 301 redirect though?

I'm no htaccess guru but does the above rule look for any domain that is NOT www.domain.com and redirect it to domain.com.

Not sure about yours, but mine redirects any domain that is NOT domain.com to domain.com (even www.domain.com).

RewriteCond %{HTTP_HOST}  !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Additionally, I redirect URLs from old domains that no longer exist to the new domain's root to prevent 404s.

will the DNS issue correct 301 redirect though?

No, DNS does not do redirects. You can use DNS if you do not mind that the site has multiple names. This solution will allow www.example.org and www.example.net to show the same website under two domain names in the address bar.

I'd recommend using @jensscherbl solution.

remie was a little faster :)

Using the htaccess 301 is the "correct" way. The official server response for a 301 redirect is a "Permanent Redirect." This means that the domain has permanently moved to a new domain. The visitor will see the new domain on page load.

Using the DNS settings (A record links a top level domain to another IP and CNAME record links a sub domain to another domain) the domain won't change which could result in search engines"double content".

What I am after is 4 domain names .co.uk, .com, .net and an old .com to redirect with a 301 to newdomain.com and only show this domain in the addressbar whatever domain is typed... Would Jens ruleset achieve this then? thanks.

Yes, Jens' rule would do just that.

I am doing the exact same thing for a number of my bigger project. Works brilliantly!

Thanks guys. Much appreciated.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details