.htaccess or httpd.conf

I need to do the job of rewriting the url.

I do not know if I should put the code in .htaccess or httpd.conf?

EDIT

What is the range of .htaccess? Will it affect all requests or only requests to a specific directory in which it is located?

+4
source share
4 answers

If you don’t have to change your rules often, you should put them in httpd.conf and disable the overrides in the top directory to which your rules apply.

AllowOverride None 

Without overriding, your apache will not scan every directory for .htaccess files, doing less overhead for each request.

If you need to change your rules, you will have to restart the apache server if you put it in your httpd.conf, unlike they are instantly detected in .htaccess files because they read them all for each request.

You can easily do this using a graceful restart using the apachectl tool to avoid disconnecting current current requests.

 apachectl graceful 

If you are not going to disable undo, you can just use .htaccess only.

Edit in response to your edit:

Say you have a request at www.example.com/dir1/dir2/dir3/file

Apache will look for the .htaccess file in all three of these directories and the root directory for the rules that will be applied to the request if you override it.

+9
source

Ease of use and maintainability IMO (just go to the directory you want, like any authorized user) = .htaccess , but this is repeated repeatedly compared to parsing once in httpd.conf , where your über-high volume level will be the best installed.

+3
source

There are three problems that are “better”:

  • performance
  • Control
  • Security

.htaccess is slower, harder to manage and potentially less secure. If you have access to httpd.conf, then placing the rules there may be easier to manage (in one place) faster ("AllowOverrides None" means that the server is not browsed in the current directory, and all the parent directories for the override file for parsing and subsequent use), and since .htaccess files are not in the website directory, they cannot be edited (and if created, they will be ignored).

+1
source

You can use both of them. IMHO .htaccess will be a little better

0
source

All Articles