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

Disclaimer: My webmastering experience is almost nil. Apologies if anything seems ignorant - if it sounds that way, it probably is.

My employer is in the middle of switching over from one version of their website to another, and for the time being would like for the old site to redirect to the new one, but have the pages of the old site preserved as a backup of sorts.

After some Google searches, I found that an easy way to perform a site-wide redirect is by adding the following line to a .htaccess file:

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

Prior to this task being given to me, the site did not have a .htaccess file, so I created one and it contains only that line. Once that file was saved, attempts to load the old site's URL yielded 500 Internal Server Error.

I am certain that I'm missing something which might be obvious to an experienced webmaster. What more do I need to do to make this redirect hold?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Redirect directive is part of mod_alias module. Make sure that you have this line (or similar) uncommented (no # in front) in your httpd.conf file:

LoadModule alias_module modules/mod_alias.so

Another possible reason: add trailing slash / if redirecting to the root folder:

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

In any case -- you should check your Apache's error log for details.


UPDATE: If you have full control over your server, make sure that you have AllowOverride All directive in your Apache config file (httpd.conf or httpd-vhost.conf), for example inside appropriate <VirtualHost>:

<Directory "/path/to/website/root">
  AllowOverride All
</Directory>
share|improve this answer
    
Thank you for the advice, especially with error logs - I reviewed the logs and found "Redirect not allowed here" in most of the most recent entries. I am still getting this error after making both the changes you suggested and the ones Paul suggested in his answer. –  asfallows Jul 11 '11 at 16:09
1  
@asfallows Contact your hosting company then -- they have quite restrictive set up and that should tell you what can be done. That's for shared hosting scenario. In case if you have full control over the server, make sure that you have AllowOverride All directive in your Apache config file, for example (inside appropriate <VirtualHost>): <Directory "/path/to/website/root"> AllowOverride All </Directory> –  LazyOne Jul 11 '11 at 16:18
    
That did it - the old web server is a local machine, so I made that edit, restarted httpd, and the redirect works. Thanks for the help! –  asfallows Jul 11 '11 at 17:08

Despite this probably being a common requirement I can't find another question just like it, so here's what to put in your htaccess file. If you want to keep the part of the url after the slash (so olddomain.com/something redirects to newdomain.com/something) do this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

If you want the redirect to just take them to the home page then use this:

RewriteRule (.*) http://www.newdomain.com/ [R=301,L]
share|improve this answer
    
Paul, I changed my htaccess to these lines (using the latter option for the third line, since that's what I need for this case), and I am still getting 500 Internal Server Errors. error.log tells me "RewriteEngine not allowed here" –  asfallows Jul 11 '11 at 16:07

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.