Home > Back-end >  Htaccess rewrite condition for files with no file extension
Htaccess rewrite condition for files with no file extension

Time:05-19

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.

CodePudding user response:

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