Htaccess & mod_rewrite


#1

To keep things tidy, I have a deep folder heirachy and shallow shortcuts, ie for my random avatar script I have “/projects/rav/rav.php?user=Shish”, but use mod_rewrite to make it accessable as “/rav/Shish.png”. I have it working on my test server, with the rewrite commands inside a virtualhost in the main apache config – but since moving to dreamhost and a per-directory .htaccess, I can’t get anything to happen. The .htaccess file is in the root web folder, it’s contents being thus:

RewriteEngine on
RewriteBase /

RewriteRule ^/rav/(.*).(jpg|png|gif|jpeg)$ /projects/rav/rav.php?user=$1 [L]
RewriteRule ^/rav /projects/rav/index.php [R]

but both “/rav/” and “/rav/.png” still give 404s :frowning:


#2

There’s a long technical answer to this that I can’t be bothered to type out right now (if you’re curious, read the mod_rewrite documentation) but the short answer is that you need to drop the leading slash off the pattern you’re matching against when using per-directory (ie, in .htaccess) rules.

So, this:

RewriteRule ^/foo /bar … should be this:

RewriteRule ^foo /bar This bit me too when I moved from running my own web server to using shared hosting, as I had never bothered using .htaccess much when I was able to use httpd.conf.


If you want useful replies, ask smart questions.


#3

all working now, thank you :slight_smile: