Why doesn't my htaccess redirect work?

21,940

Solution 1

Make sure that

AllowOverride All

is set in the httpd.conf file!

But if you have access to the main config file, I would recommend doing the configuration there rather than in an .htaccess file - the .htaccess file will slow the server down. This may not be an issue if you have a very low server load, but it's just as well to use the best practices even on smaller projects.

Solution 2

My httpd.conf file was not configured on this server to AllowOverride in the site directory. It was set to 'none' which I changed to:

AllowOverride All
Share:
21,940

Related videos on Youtube

willdanceforfun
Author by

willdanceforfun

Updated on September 18, 2022

Comments

  • willdanceforfun
    willdanceforfun over 1 year

    I have setup a simple htaccess redirect which looks like this (this is the whole .htaccess file):

    Options +FollowSymLinks
    
    RewriteEngine On
    
    Redirect 301 /something http://something.com/something.php
    

    If I then load the site which contains this .htaccess, ie, myredirectsite.com/something I end up with the following 404:

    The requested URL /something was not found on this server.
    
    Apache/2.2.3 (Red Hat) Server at myredirectsite.com Port 80
    

    And the logs:

    [Tue Jul 10 14:25:46 2012] [error] [client xx.xx.xxx.xx] File does not exist: /home/sites/scp/something

    Something is not a file, and something does not exist. I have assumed I could use Redirect the same as a Rewrite but it looks like the redirect needs to be for a file that actually exists?

    I created the file 'something' and it just attempts to load the blank file. No redirect.

    What am I missing in getting this working?

    • Admin
      Admin almost 12 years
      Debug logs, for a start.
    • Admin
      Admin almost 12 years
      Edit your question to include additional information, don't put it in a comment.
    • Admin
      Admin almost 12 years
      The Redirect directive isn't part of mod_rewrite, so if that's all you're doing, you should remove the "RewriteEngine on" directive.
    • Admin
      Admin almost 12 years
      Thanks for that @JennyD. I've removed it - it seems though that perhaps my server isn't even attempting to load the htaccess.
    • Admin
      Admin almost 12 years
      Do you have access to the main server configuration? Does it have AllowOverride set - if so, to what?
    • Admin
      Admin almost 12 years
      It was set to None @JennyD. All servers I've used in the past have not had it set to None by default. All fixed now - thanks for your input!
    • Admin
      Admin almost 12 years
      If you add an answer to do this I will mark it as the correct answer - cheers.
    • Admin
      Admin almost 12 years
      Done, happy it worked!
  • Pozinux
    Pozinux over 4 years
    Resolved my problem thanks. Mine was in apache2.conf. Don't forget to reload the apache2 service.