Pergunta

I need to redirect my website to a new domain name but I want it to also redirect all of the pages. I want www.myoldsite.com/ to redirect to www.mynewsite.com/ but I also want all of the pages to redirect.

For example: www.myoldsite.com/faq to redirect to www.mynewsite.com/faq and so forth and so on. I know how to do it by doing each individual page but I have a lot of pages. How do I rewrite the 301 for it to basically change the root domain name but keep the directories and pages the same? Thanks a million!

Foi útil?

Solução

You just need this in the htaccess file in your old domain's document root:

Redirect 301 / http://www.mynewsite.com/

If both your old site and new site share the same document root, then you need mod_rewrite instead:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myoldsite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mynewsite.com/$1 [L,R=301]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top