Forum Moderators: phranque

Message Too Old, No Replies

Convert .htaccess to httpd.conf: should be simple but fails

My life is fail right now

         

httpdconf

10:59 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



I have been trying for two days straight to convert this relatively simple subdirectory/.htaccess file rewrite:


#The ColdBox index.cfm/{path_info} rules.
RewriteRule ^$ index.cfm [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.cfm/%{REQUEST_URI} [QSA,L]

Into a httpd.conf version. Normally the above .htaccess would reside in a subdirectory like /wiki/.htaccess and direct all traffic through /wiki/index.cfm.

For a variety of reasons, I can't use .htaccess in this instance. I have tried probably 100 permutations in the httpd.conf and am having zero luck. It either comes back as 403 or 404. I have turned on rewrite logging and the paths that should be rewritten just pass through unaffected with my attempts.

It should be so simple but I just can't get it to work, help! :(

jdMorgan

2:10 am on Aug 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that if you have put this code in a server config file, but NOT within a <Directory> container, then all patterns examined by RewriteRule will need the full URL-path to be matched.

In the simplest case, this would mean that for files in the 'home page' directory "example.com/"

RewriteRule ^$ blah [L]
in .htaccess would become
 RewriteRule ^/$ /blah [L] 

in httpd.conf
and
 RewriteRule ^(.*)$ index.cfm/$1 [QSA,L] 

in .htaccess would become
 RewriteRule ^/(.*)$ /index.cfm/$1 [QSA,L] 

-or equivalently-
 RewriteRule ^(.*)$ /index.cfm$1 [QSA,L] 

in httpd.conf

This is because --as noted in the Apache documentation-- .htaccess is a per-directory config file, while the server config files are... well... server config files. Therefore, in .htaccess, RewriteRule cannot 'see' the URL-path to the current .htaccess file's directory -- It doesn't know the path, and doesn't need to know the path, making coding in previously-rewritten or aliased environments easier, and improving security.

Jim

httpdconf

2:27 am on Aug 26, 2009 (gmt 0)

10+ Year Member



Jim,

Thanks for the quick response - I have tried both approaches, inside the directory container as a local config option and in the general vhost container with a full path. I've tried with and without leading slashes... I assume in the examples above that a subdirectory would simply include the subdirectory name at the beginning of the Rewriterule match correct?

jdMorgan

2:31 am on Aug 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteRule ^/full-path-from-document-root-to-directory/filname.filetype$ /full-path-from-document-root-to-directory/filname.filetype$ [L]

[added] And be sure to completely flush your browser cache after any change to your server-side code, and to restart Apache after any change to any server config files. [/added]

Jim

httpdconf

6:00 am on Aug 26, 2009 (gmt 0)

10+ Year Member



Does an httpd reload work or must it be httpd restart? I'll give these a shot - thanks Jim!