How to rewrite a URL if its character length is less than a certain number of characters

Viewed 1229

I have the following code in my .htaccess file that allows URLs that contain only letters, numbers, underscores or dashes to access my page (named "available"):

RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^[a-zA-Z0-9_-]+$ /available.shtml [L]

So for example, mywebsite.com/abc goes through, mywebsite.com/ABC goes through, mywebsite.com/123 goes through, mywebsite.com/aBc123 goes through (you get the point). Any requested url that contains symbols produces an error page.

This works great, but I also want to restrict the character length to no more than 25 characters (Meaning the requested URL must contain only letters, numbers, etc. AND be less than 25 characters long. How can I do this? I tried using:

RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_-]{25,})+$ /available.shtml [L]

but this makes it have to be more than 25 characters not less.

edit (referring to comment): error when adding period

1 Answers
Related