LGP
LGP

Reputation: 21

RewriteCond/RewriteRule with case-insensitive and trailing slash functionality?

I got problems with the following two lines:

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+[^/])$ /$1.html [L]

Goal: Redirecting "domain.tld/test/" (only if test.html exists) so that it outputs the contents of "domain.tld/test.html".

Thanks!

** I couldn't get RewriteMap lowercase int:tolower to work, any help appreciated.

Upvotes: 2

Views: 1317

Answers (2)

Naidim
Naidim

Reputation: 7166

Use [NC] for case insensitive checking.

See here for the trailing slash issue: Mode Rewrite; with/without trailing slash on end of url?

Upvotes: 1

Gumbo
Gumbo

Reputation: 655319

Try this:

RewriteRule (.+)/$ $1
RewriteCond %{DOCUMENT_ROOT}/${tolower:$1}.html -f
RewriteRule ^(.+[^/])$ /$1.html [L]

Furthermore RewriteMap can only be used in the server configuration or virtual host context but not in a .htaccess file. So you need to define the rewrite map there.

Upvotes: 0

Related Questions