I have a very simple .htaccess file that is designed to redirect any request to index.php if the file does not exist and is not a directory.
[Before proposed changes]
<IfModule mod_rewrite.c> RewriteEngine On #REWRITE RULES #--------------------- #RULE COMPLETEREWRITE RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.* index.php </IfModule>
[Following recommended changes]
<IfModule mod_rewrite.c> RewriteEngine On #REWRITE RULES #--------------------- #RULE COMPLETEREWRITE RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [L] </IfModule>
(No change between htaccess changes)
Currently, it redirects to index.php regardless of whether the file exists or not. Can anyone explain why this could be?
This seems like a dumb question, but I did a bit of work and changed a bit.
This works in Apache 2.4 under Ubuntu with mod_rewrite enabled, I hope I hope so.
Case scenario:
A file in '/resource/img/panoramas/1.png' exists. It is checked in my VM file system through a local file browser, SSH and FTP.
Prior to the implementation of the htaccess file, this file was deleted remotely. I have a cached version to prove it.
After implementing the htaccess file, any attempt to get along this path returns index.php.
================
The kernel for my CMS contains methods that create headers when using rewrite. If I land on index.php myself, I will not mark the rewrite (as expected). If I hit any other path in this directory, I believe in index.php with a rewrite flag (partially expected). It should not be if the file exists, but still meets contrary to expectations.
It may also be noted that this htaccess file was created automatically from the web.config (IIS) file, and in IIS these rules and my CMS work completely as expected.
Finally (unlike best practices) the entire chmod'ed directory to 777 to exclude the possibility of file inaccessibility.
php apache .htaccess mod-rewrite
DigitalJedi805
source share