Forum Moderators: phranque

Message Too Old, No Replies

.htaccess or http.conf?

         

moroandrea

9:53 am on Nov 5, 2010 (gmt 0)

10+ Year Member



Hi All,

Given a RewriteRules scenario, where I need to make some URL rewriting, I'm trying to understand if there is better to place the rules in the root .htaccess file or in the http.conf file.

As far as my understanding go, it looks like the .htaccess file is read every single request, while the http.conf is read once then cached.

As the RewriteRules are not supposed to change, is there a real advantages use one file rather than another?

Many thanks for your help.

g1smd

7:30 pm on Nov 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Placing the rules in http.conf will be more efficient, but a server restart is required after each and every change.

tangor

6:41 am on Nov 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



.htaccess is a good place to test rule changes which might ultimately move to http.conf. Roll back is easy and no restarts required.

And if nobody said "Hello!" welcome to Webmasterworld!

moroandrea

1:54 pm on Nov 9, 2010 (gmt 0)

10+ Year Member



Hi All,

thanks for you answer. Both your answer makes perfectly sense. However, I have a trouble now. What it was working fine in the .htaccess file, is no longer working in the http.conf.

I placed excatly the same rules including the RewriteEngine on into the most appropriate

<Directory ...>\</Directory>

section, but the server is not able to recognize the inexistent path, and instead of being redirected to the new location I get the 404 error page.

What is the fault? What should I need to change in my file?

g1smd

6:09 pm on Nov 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In .htaccess, localised paths are stripped off (even the leading slash for root requests), whereas in http.conf you will need the leading slash to be included in the patterns.

That is, for requests for
example.com/folder/page


http.conf
will need:
^/folder/page


example.com/.htaccess
will need:
^folder/page


example.com/folder/.htaccess
will need:
^page

moroandrea

7:50 pm on Nov 9, 2010 (gmt 0)

10+ Year Member



Hi G1smd,

it looks the problem is something different. The rules I created are not triggered at all in the http.conf.

Even a stupid RewriteRule without a Condition is not considered at all.

moroandrea

3:37 pm on Nov 10, 2010 (gmt 0)

10+ Year Member



Ok I have an update. I have finally realized that in the httpd.conf file the server perform a lookup for the file and directory and because they don't exist, in the acces.log file I see a 404 error code fired.

How can I say to the server to skip file/folder check and execute the redirection immediately?

I tried with the standard

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

but it looks like this is not the proper way because the rules are ignored.

g1smd

4:33 pm on Nov 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Wrong order, the server should automatically process the mod_Rewrite code first.

If it has proceeded on to the next stage and is looking for files on the server then the mod_rewrite is faulty in some way.

Make sure that the code is in the correct "container" in order to be evaluated for the right URL requests received by the server.

The -f and -d "exists" checks are used when you want particular requests to NOT be processed by mod_rewrite so that the server CAN serve the content of the matching file from the server harddrive.

moroandrea

4:51 pm on Nov 10, 2010 (gmt 0)

10+ Year Member



Hi G1smd,

well that's my file.

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?test\.eu(\.|\.?:[0-9]+)?$ [NC]
RewriteRule ^(.*)?$ [test.com...] [L,R=301]
#the rule above works fine

RewriteCond %{HTTP_HOST} ^(www\.)?test\.(.*)(\.|\.?:[0-9]+)?$ [NC]
RewriteRule ^/fcp/categorylist/dept/children_girls_2-6year/?.*?$ [%2.test.com...] [L,R=301]

#the rule above is ignored. If I request the [test.com...] the server will come up with a 404 and it doesn't execute the redirect.
</Directory>

Can you shed some light on this, please?

Thanks

topr8

6:47 pm on Nov 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> .htaccess is a good place to test rule changes which might ultimately move to http.conf. Roll back is easy and no restarts required.

i disagree! as by this method you lose the speed advantage of http.conf
if .htaccess is not 'turned off' (eg. When AllowOverride is set to allow the use of .htaccess files) as the web server looks for an htaccess file in every directory of the path, even if it doesn't exist.

moroandrea

8:19 pm on Nov 10, 2010 (gmt 0)

10+ Year Member



Hi topr8,

how can I disable the .htaccess lookup? Do you have any idea on how to solve the other issue?

Elsmarc

4:50 am on Nov 11, 2010 (gmt 0)

10+ Year Member



Placing the rules in http.conf will be more efficient, but a server restart is required after each and every change.
Naw, using the command line interface just restart Apache with something like:

apachectl -k graceful

or

killall httpd
restart httpd

topr8

9:27 am on Nov 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



AllowOverride None
will prevent the lookups of htaccess.

moroandrea

12:00 pm on Nov 11, 2010 (gmt 0)

10+ Year Member



I got it. The problem was I was pasting the rules into the Directory section, while that kind of rules require to be put outside it.