Redirect with htaccess with first letter forced to lowercase to identify file name

regex .htaccess

78 观看

1回复

186 作者的声誉

I have the following rule:

RewriteRule ^([a-z])([\w-]+)/?$ $1.php?var=$2 [L,QSA,NC]

This redirects /fH128 to f.php?var=H128. I would like to be able to have the first character, which identifies the file name, be uppercase, but then redirected to this filename in lowercase. Thus /FH128 would redirect to f.php?var=H128.

I tried the following, but neither work:

RewriteRule ^([a-z])([\w-]+)/?$ ${lowercase:$1}.php?var=$2 [L,QSA,NC]
RewriteRule ^([a-z])([\w-]+)/?$ {lowercase:$1}.php?var=$2 [L,QSA,NC]
作者: James Hawkins 的来源 发布者: 2017 年 12 月 27 日

回应 1


0

559431 作者的声誉

Inside your Apache config files e.g. httpd.conf or virtual host config (but not .htaccess) define this RewriteMap:

RewriteMap lowercase int:tolower

Then inside .htaccess use your rule as:

RewriteRule ^([a-z])([\w-]+)/?$ ${lowercase:$1}.php?var=$2 [L,QSA,NC]
作者: anubhava 发布者: 2017 年 12 月 31 日
32x32