Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess or httpd.conf

I need to do a url-rewriting job now.

I don't know whether I should put the code into a .htaccess or httpd.conf?

EDIT

What's the effecting range of .htaccess?Will it affect all requests or only requests to the specific directory it's located?

like image 881
Paypal Avatar asked Nov 11 '09 05:11

Paypal


People also ask

What is the difference between an httpd conf file and a .htaccess file used for in an Apache Web server?

httpd. conf is read in when Apache starts or if you run a 'reload'. . htaccss is a per-directory configuration file for Apache.

When should I use htaccess?

. htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system.

Where is .htaccess file in httpd?

htaccess file can be found at /opt/bitnami/APPNAME/. htaccess. Some applications do not have the /opt/bitnami/apache2/conf/vhosts/htaccess/APPNAME-htaccess. conf file.

Is .htaccess necessary?

If you are using shared hosting you will likely need to use a . htaccess file to make configuration changes to your server. If you are using a virtual private server or a dedicated server, you should have access to the main server configuration file (usually called httpd. conf).


3 Answers

If you wont have to change your rules very often, you should put them in the httpd.conf and turn off overriding in the top directory your rules apply to

AllowOverride None

With no overriding, your apache will not scan every directory for .htaccess files making less of an overhead for each request.

Whenever you do have to change your rules, you will have to restart your apache server if you put it in your httpd.conf as opposed to them being instantly detected in .htaccess files because it reads them all on every request.

You can easily do this using a graceful restart with the apachectl tool to avoid cutting off any current requests being served.

apachectl graceful

If you aren't going to turn override off, you might as well just use .htaccess only.

Edit in response to your edit:

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

Apache will look for a .htaccess file in all 3 of those directories and the root for rules to apply to the request if you have overriding allowed.

like image 126
Mike Avatar answered Oct 02 '22 08:10

Mike


Ease of use and IMO maintainability (just go to the dir you want as any permissioned user) = .htaccess but that is parsed repeatedly vs. the parse once in httpd.conf where your über-high volume would be best set.

like image 30
Jé Queue Avatar answered Oct 02 '22 07:10

Jé Queue


There are three issues here in terms of which is "better":

  • performance
  • management
  • security

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

like image 20
jeffmcneill Avatar answered Oct 02 '22 08:10

jeffmcneill