Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to remove subdirectories using mod_rewrite in .htaccess Reply To: How to remove subdirectories using mod_rewrite in .htaccess

#170969
__
Participant

By the way, I’ve stumbled upon a code like this:
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

A RewriteCond is a conditional statement. It’s like an if: if the condition is true, then the following rule will be applied.

This one compares the URI that the user requested (the Apache variable%{REQUEST_URI}) to a pattern.

! means “not”. Basically, it means we are looking for URIs that do not match this pattern, instead of ones that do.

\. means a literal dot (.)
(The backslash is an escape character: in a regular expression, . means “any character.” Escaping it makes it match an actual dot.)

[a-zA-Z0-9]{1,5} means 1, 2, 3, 4, or 5 alphanumeric characters.

| means “or”: so, we’re matching either the first part of the pattern, or the next.

/ is just a literal slash.

$ is an “end-of-line” anchor. Effectively, it means that nothing else can come between the previous pattern and the end of the URI.

Put all together, this means we are looking for a URI that “does not end with a dot followed by 1-5 alphanumeric characters or a slash.” My guess is that it’s looking for urls that (1) are not directories and (2) do not include file extensions.

Why is another issue; this pattern seems vague enough that it probably has false results at times. Is it something that you’re trying to use? if so, what for?