Htaccess rewrite condition for files with no file extension

Viewed 51

I have a rewrite condition for specific file types like so:

RewriteCond %{REQUEST_URI} .*(\/|.htaccess|.htpasswd|.ini|.log)$

This works fine for files with those file extensions however I can't figure out how to make it also match files with no extension.

Eg. cats.com/regularfile.ini and cats.com/regularfile should both trigger the condition.

Any ideas?

I am fine if the no extension condition needs to be separate but it should trigger whether the file actually exists or not as my current rule does.

1 Answers

I can't figure out how to make it also match files with no extension.

You may use it like this:

RewriteCond %{REQUEST_URI} ^/(?:[^.]+|.*(/|\.(?:htaccess|htpasswd|ini|log)))$

[^.]+ match 1 or more of any character that doesn't have dot.

Related