Is restarting apache server required for htaccess rules?

Do I need to restart apache server to use RewriteRules in htaccess?



Restart apace server

New users often ask whether they should restart apache server after making changes in htaccess rules. I see a similar question being asked more and more often on question and answer sites like Stackoverflow. So I decided to write my own post that will give you a clear overview .
In this post I will answer wether you need to restart your server or not with some explanations .

If you do not want to read the entire post or you are just looking for an instant answer, then


The short and simple answer is : NO

You don't need to restart apache server to use RewriteRules.



Why?

Because webserver reads htaccess each time a file is requested from server.
When you request something from apache web server , your server reads your htaccess file before serving the request and this way your htaccess file is automatically updated.

Since an htaccess file gets updated automatically , you do not need to restart the server. The changes you make in your htaccess files are auto applied when you request an URI. For example: if you add a new rule to redirect your site to non www version, you can simply test your rule by typing your URL in a web browser without needing to restart the server.

What if I am using RewriteRules in a server.config file?




If your rules are in a server.config file then restating the server is required. If you make some changes to your config file and don't restart the server then those changes wont apply to your server. The main diffrence between htaccess and server.config file is an htaccess gets updated automatically while server.config files updates only once when you restart your server. Your webserver remembers the contents of server.config untill you manually restart it.


So finally, you must restart your apache web server after making changes in your server config file. But if you are using htaccess then you can simply save the code and type your URL to test your new rules.

Post a Comment

0 Comments