#make get request clean RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^cms/tests/([0-9]+)/([a-zA-Z0-9_-]+) cms/tests/index.php?survey=$1&mode=$2 [NC,L]
The second condition is never successful so the rule is not processed.
The second condition (that supposedly checks that the request + .php
exists) is not what you should be doing here. If anything, you would need to check that the request does not map to a file. For example:
RewriteCond %{REQUEST_FILENAME} !-f
However, if you restrict the regex in your RewriteRule
pattern by appending a $
(end-of-string anchor) then you can remove that condition altogether. For example:
#make get request clean
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cms/tests/([0-9]+)/([a-zA-Z0-9_-]+)$ cms/tests/index.php?survey=$1&mode=$2 [NC,L]
A request that matches the regex as stated could not map to a real file (unless you have extensionless files).
Aside:
# clean up file extensions .php only RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L]
The second condition in your first code block is also not strictly correct and will fail under certain conditions, because the filesystem check is not necessarily the same as the file you will ultimately rewrite to, which could result in a 404 or 500 (rewrite loop) depending on your file structure. (This code block is surprisingly common, but issues relating to this keep on cropping up.)
This should really be written more like this:
# clean up file extensions .php only
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
Now, the condition %{DOCUMENT_ROOT}/$1.php
matches the rewrite substitution $1.php
. (Assuming the .htaccess
file is in the document root.)
See my answer to the following question on ServerFault with a detailed explanation of this change: https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error