Link to home
Start Free TrialLog in
Avatar of Ludwig Diehl
Ludwig DiehlFlag for Peru

asked on

How to centralize .htaccess rules in httpd.conf

Hello everyone!

I was wondering how to set a rewrite rule on the httpd.conf rather than placing a .htaccess on every location

My directory structure:
https://mydomain.com/services/name/rest/index.php
https://mydomain.com/services/name/rest/.htaccess

How to invoke:
https://mydomain.com/services/name/rest/operation/value

My .htaccess content:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?s).*)$ index.php?_action=$1 [QSA,L]
</IfModule>
Avatar of Dr. Klahn
Dr. Klahn

Just move that code into httpd.conf.

In general it is not necessary to conditionalize on whether mod_rewrite is available.  mod_rewrite is compiled in by default unless Apache was rebuilt specifically without it.
Avatar of Ludwig Diehl

ASKER

it is not that simple because I only want to apply that rule on a certain condition.

So the condition should be something like this:

https://mydomain.com/services/*/rest/*

Only when /services/*/rest matches
If I understand what you're asking, take a look at how Ubuntu (and all Debian derivatives) handle this.

They provide a directory called /etc/apache2/sites-available for virtual hosts.

Then for other common directives, like logging, create a logging.conf file in /etc/apache2 + include it in every virtual host setup file.
Of course I understand what I am asking. I yeah, I like the way debian and Suse handle this. But it is just a matter of creating such a folder and placing there all my vhosts conf files separately. I was just wondering how to achieve what I asked for using wildcards.
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you everyone. In the end I had to create separate files.