The eternal fight between admins and computers

(and very often users, as well)

Archive for the ‘Apache’ Category

Mod_Rewrite forbidden 403 with Apache 2.2.8

Posted by rga on June 10, 2008

If you get a message like this and you are sure that your mod_rewrite rules are OK:

Tue Jun 10 11:18:59 2008] [error] [client 192.168.1.85] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/enterprise/file.html

You need to enable FollowSymLinks in the directory that uses mod_rewrite, if not, you will get a friendly 403 error message :)

<Directory /path/of/your/dir>
Options -All
Options +FollowSymLinks
</Directory>

To enable globally, use httpd.conf with

<Directory />
 Options +FollowSymLinks
</Directory>

See you!

Posted in Apache, Debian, Linux, Tips, Web systems | Leave a Comment »

Apache, mod_rewrite and multiples RewriteCond

Posted by Vide on April 21, 2008

If you don’t kown Apache’s mod_rewrite, then you should, because it’s a very nice and flexible piece of software when you need to do URL mangling and L7 HTTP proxy. You cand do all sort of redirections, set cookies based on data like incoming URL, browser version etc or even set an environment variable with a value matching a regexp pattern.

You can find on the net very good tutorials about mod_rewrite, so I won’t waste your bandwith with a worse explication… anyway, today I want to share with you a little tip I found while working with mod_rewrite.

Imagine you need to write a rule involving two or more RewriteCond, and you want to use RewriteCond’s pattern matching backreferences in your rule (with %1, %2 … %N). Well, you have to keep in mind that you can use a backreference only from the LAST RewriteCond you have used. Example:

RewriteCond %{HTTP_HOST} (.*)\domain\.tld
RewriteCond %{REQUEST_URI} ^/(css|images|js)/
RewriteRule ^/(.*) http://www.domain.tld/%1/static/$1 [L]

At a first glance, if the original URI is

http://foo.domain.tld/js/script.js,

then the rewrited URI should be something like

http://www.domain.tld/foo/static/script.js

but that’s not true, because mod_rewrite is evaluating only the last RewriteCond! So, eventually the URL will be

http://www.domain.tld/js/static/script.js

that’s not what we (or at least I) were expecting. The solution, in this case, is to join the REQUEST_URI condition with the RewriteRule:

RewriteCond %{HTTP_HOST} (.*)\domain\.tld
RewriteRule ^/(css|images|js)/(.*) http://www.domain.tld/%1/static/$2 [L]

but you can easily see that it’s something you should be aware of when the conditions are more variegate.

Posted in Apache, Software, Tips, Web systems | Leave a Comment »