Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache .htaccess rewrite - can I move this into httpd.conf

Below is the only code I have in the .htaccess file with apache 2.2.

I've read that its a performance impact to use a .htacess and better if this this can be run out of httpd.conf. Therefore is it possible for me to add this into httpd.conf? If so where would I put it?

Would it need to go into the VirtualHost for each Host that needed it (in my case a lot of hosts) or could it go generically into httpd.conf so it applies to all hosts?

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
like image 501
user1105192 Avatar asked Jun 17 '13 04:06

user1105192


People also ask

Does .htaccess override httpd conf?

htaccess file will only override the mod_rewrite directives in httpd. conf if the directives in httpd. conf are also in a <Directory> container.

Where do I put rewrite rules in httpd conf?

A rewrite rule can be invoked in httpd. conf or in . htaccess . The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.

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

Configuring your Apache web server: conf and . htaccess are text-based configuration files for an Apache web server. The configurations in httpd. conf apply to the entire server, and those in htaccess only to the folder it's located in (and all of its subfolders).

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.


1 Answers

.htaccess provides configuration for a directory, while httpd.conf provides an overall configuration. Of course, you can move content from .htaccess to httpd.conf. You can find more about .htaccess here: Apache HTTP Server Tutorial: .htaccess files

Take your .htaccess for example:

Contents of .htaccess file in /www/htdocs/example

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Section from your httpd.conf file

<Directory /www/htdocs/example>
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-l
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
</Directory>
like image 114
Tony Chen Avatar answered Nov 15 '22 20:11

Tony Chen