Forum Moderators: phranque

Message Too Old, No Replies

Rewrite works in httpd.conf but not in .htaccess

mod_rewrite htaccess rewriterule

         

mattdeclaire

12:03 am on Apr 26, 2007 (gmt 0)

10+ Year Member



My first attempt at mod_rewrite

I've got the following working in httpd.conf


RewriteEngine On
RewriteRule ^/download/(.*)$ /download/getFile.php?id=$1

Example request: /download/dude
Served: /download/getFile.php?id=dude

I'm trying to do the same thing in an .htaccess file. I've put it in
the /download/ directory:


RewriteEngine On
RewriteRule ^(.*)$ /download/getFile.php?id=$1 [L]

I commented out my httpd.conf code, put the .htaccess in place and
restarted the server, but the request yields a 404.

I've searched through forums, but I feel like I am missing a simple detail.

jdMorgan

12:21 am on Apr 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that you've got Options +FollowSymLinks set for that directory path:

RewriteEngine On
RewriteCond $1 !^getFile\.php$
RewriteRule (.*) /download/getFile.php?id=$1 [L]

In .htaccess, the path to the current directory is stripped from the URL-path used to match the pattern, and added to the URL-path in the substitution (for an internal rewrite).

Also in .htaccess, you must explicitly prevent recursion by disabling the rule if the URL is already getFile.php.

Jim

[edited by: jdMorgan at 12:21 am (utc) on April 26, 2007]

mattdeclaire

9:24 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Well, it turns out I had:

AllowOverride None

in my sites <Directory "/Users/matt/Sites"> section.

I had been through my httpd.conf before, and messed with that setting, but I had only made changes to:

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

For some reason I dismissed it, thinking that if could could make Rewriterules work in the httpd.conf, I should be able to put them in an .htaccess file. I accidentally and specifically ignored the setting disabling the .htaccess access.