Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you have to restart apache to make re-write rules in the .htaccess take effect?

I have pushed my .htaccess files to the production severs, but they don't work. Would a restart be the next step, or should I check something else.

like image 420
Jesse Hattabaugh Avatar asked Sep 27 '08 00:09

Jesse Hattabaugh


People also ask

Do you need to restart Apache for .htaccess changes?

No, you will not need to restart Apache. You will need to "hard refresh" your web page to see the changes.

How long does it take for htaccess to change effect?

htaccess files follow the same syntax as the main configuration files. Since . htaccess files are read on every request, changes made in these files take immediate effect.

How do I know if htaccess rewrite is working?

Save the file and type the URL yoursite.com/foobar/ . If the reditect works and the URL gets redireted to the homepage of example.com then it's clear that your htaccess is working and being read by your Apache server. If it still doesn't work then the problem might be that your hosting provider has not enabled it.

What happens when you restart Apache?

restart : Stops and then starts the Apache service. reload : Gracefully restarts the Apache service. On reload, the main Apache process shuts down the child processes, loads the new configuration, and starts new child processes.


3 Answers

A restart is not required for changes to .htaccess. Something else is wrong.

Make sure your .htaccess includes the statement

RewriteEngine on

which is required even if it's also present in httpd.conf. Also check that .htaccess is readable by the httpd process.
Check the error_log - it will tell you of any errors in .htaccess if it's being used. Putting an intentional syntax error in .htaccess is a good check to make sure the file is being used -- you should get a 500 error on any page in the same directory.

Lastly, you can enable a rewrite log using commands like the following in your httpd.conf:

RewriteLog "logs/rewritelog"

RewriteLogLevel 7

The log file thus generated will give you the gory detail of which rewrite rules matched and how they were handled.

like image 70
TomG Avatar answered Oct 19 '22 10:10

TomG


No:

Apache allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called .htaccess, but any name can be specified in the AccessFileName directive... Since .htaccess files are read on every request, changes made in these files take immediate effect...

like image 52
Milen A. Radev Avatar answered Oct 19 '22 08:10

Milen A. Radev


From the apache documentation: Most commonly, the problem is that AllowOverride is not set such that your configuration directives are being honored. Make sure that you don't have a AllowOverride None in effect for the file scope in question. A good test for this is to put garbage in your .htaccess file and reload. If a server error is not generated, then you almost certainly have AllowOverride None in effect.

like image 19
PiedPiper Avatar answered Oct 19 '22 10:10

PiedPiper