Brad
Brad

Reputation: 950

Htaccess rewrite condition for files with no file extension

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.

Upvotes: 2

Views: 487

Answers (1)

anubhava
anubhava

Reputation: 785266

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.

Upvotes: 1

Related Questions