Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need to (permanent) redirect all of the following:

  1. www.domain.com
  2. www.domain.com/folder
  3. sub.domain.com
  4. sub.domain.com/folder

Basically all URLS that are reachable without being intended to: www.newdomain.com, I want to do this within Apache and using the mod_rewrite module via the htaccess file.

share|improve this question
add comment

4 Answers 4

Use an 301 redirect with your .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newsite.com/$1 [R=301,L]
share|improve this answer
add comment

Put this in your .htaccess:

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

Source

share|improve this answer
add comment

To redirect all files on your domain use this in your .htaccess file if you are on a unix web server:

redirectMatch 301 ^(.*)$ http://www.domain.com

redirectMatch permanent ^(.*)$ http://www.domain.com

share|improve this answer
add comment

It would be better to redirect (forward) your domain at your registrar and forward the old domain which includes all sub domains to the new domain. This way your server is not handling all the requests which takes up resources.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.