Rectangle 27 0

php .htaccess Multiple Rewrite Rules with Extensions?


RewrieEngine on
# 404 any URL ending .php (ignoring any query string)
RewriteRule ^(.+)\.php$ - [R=404,L,NC]
# Rewrite any URL that does not contain a dot (.), and therefore has no extension, to ini.php
RewriteRule ^([^.]*)$ ini.php [END]

Don't turn DirectorySlash off. It's a security risk to do so (see the link) and it only applies to existing directories anyway so is not causing any problems for you. There is no space in RewriteEngine.

I am assuming it will go in a .htaccess file from what you said. It would need changing to go in the main config.

Sorry about that. Changing the plus sign for a star on the last line should sort it. I updated the answer.

Thanks for your response. I didn't actually want to disclose that I was handling php files, so I did want to go ahead and reply with a 404, though I really like your idea... It's actually kind of funny because you replied just as I found a solution... Could you look over it and see what you think for me? RewriteEngine on DirectorySlash off RewriteCond %{REQUEST_URI} (\.[php^\\/]+)$ RewriteRule ^(.*)$ - [L,NC,R=404] RewriteCond %{REQUEST_URI} !(\.[^\\/]+)$ RewriteRule ^.+$ / [L,NC] For DirectorySlash, if I turn off indexing, would it still be a security issue?

There is no reason to turn DirectorySlash off, why would you want to do it? I can't easily read the rest in a comment like that, could you post it in an update to the question please? Probably easiest is just that I update my answer to be a 404, which I'll do now.

Yeah you must have some other directives that are causing the whole URL processing phase to run through again, so the END flag ensures that it doesn't reprocess successful matches to that rule when they come back through. I'm not 100% clear on what possible causes there are for the processing phase to run through again, need to learn more on that. Glad it's working for you.

Note