three domains redirect to main domain best practice apache2
I have three domains ex: domain.com, domain.de and domain.co.uk. The com domain is a global (main) domain and the others are country specific domains. I would like to redirect the co.uk and the .de domain to domain.com/de/ and domain.com/uk/.
What's the best way to do this on apache? Using rewrite rules in htacess file? or using php? Is it better to do a 开发者_运维技巧301 redirect (SEO wise)?
Thanks for the reply's.
Definitely the best way is to use 301 redirection. This is adviced by google. Something like this in htaccess should work:
Redirect 301 / http://www.example.com/
it is better to do it on server level, not application level (apache rewrite rules than php). It is because it will be faster, and it is server's role, not application's.
However if you have one htaccess file for all domains, than you might want to use conditional statement, something like:
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Which performs 301 redirection always, when the current domain is not www.example.com. Please be aware, that example.com and www.example.com are two different things! so you should decide which one you would like to use (with or without www) and go for it.
Use apache's rewrite module. There is no need to run php interpretator.
301 should be used here but search engines will not index related domains.
精彩评论