Domanda

I have .htaccess like this.

Options FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^media/([^/]+) download.php?file=$1 [L]
RewriteRule ^json/([^/]+)/([^/]+)/([^/]+) jsonfeed.php?module=$1&method=$2&params=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?q=$1,$2,$3,$4 [NC,L]

Everything works fine until i have image with three directories. For example something like

http://localhost/upload/html/.thumbs/2.jpg

With URL similar to this last rule is applied. File exists. It loads fine without rewrite engine. What i'm doing wrong?

È stato utile?

Soluzione

The issue has to do with the fact that you used the [L] directive. The subsequent rules do not take into account whether the exists check or directory check succeed or fail. One solution is as follows:

Options FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^media/([^/]+) download.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^json/([^/]+)/([^/]+)/([^/]+) jsonfeed.php?module=$1&method=$2&params=$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?q=$1,$2,$3,$4 [NC,L]

A more compact solution is to deal with the existing things first, like so:

Options FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^media/([^/]+) download.php?file=$1 [L]
RewriteRule ^json/([^/]+)/([^/]+)/([^/]+) jsonfeed.php?module=$1&method=$2&params=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?q=$1,$2,$3,$4 [NC,L]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top