Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Put this in your .htaccess:

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


share|improve this answer

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

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

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

Your Answer


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.