Here is what I am trying to do:
- When a file is requested from filesystem and it does not exist, rewrite the URL to /index.php?404
- When file is requested and it does exist in filesystem, rewrite the URL to /index.php?file
- In every other case rewrite the URL to /index.php?data
But I am getting 500 errors as a result, does anyone know where the problem might be? I have used RewriteEngine in the past, but it’s still a bit confusing to me regarding how to use it for special cases like this.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} (.*\.([a-zA-Z]{2,4}))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php?404 [L]
RewriteCond %{REQUEST_FILENAME} (.*\.([a-zA-Z]{2,4}))$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* ./index.php?file [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php?data [L]
You have infinite rewrite loop. To solve — add extra condition to not rewrite already rewritten URLs .. or at least ignore requests to
index.php.One of the possible approaches:
P.S.
How L flag works: RewriteRule Last [L] flag not working?