Apache: How to rewrite URL with no file extension and ignore case?

﹥>﹥吖頭↗ 提交于 2019-12-05 23:57:11

I finally figured this one out. Well, at least part of it. It turns out that the 'MultiViews' option was responsible for resolving files without the '.php' extension. That, in combination with these two lines in my '/etc/apache2/sites-available/default' file, gives me the behavior I desire:

RewriteEngine On
RewriteRule ^/(.*)$ /${lc:$1}

Unfortunately, I haven't been able to determine why my .htaccess file is ignored when it has the above rules, but not ignored when it has gibberish.

EDIT: OK, I figured out why the .htaccess file wasn't working. It was being read, but the second rule wasn't being matched. Here's why, according to the Apache documentation:

The removed prefix always ends with a slash, meaning the matching occurs against a string which never has a leading slash. Therefore, a Pattern with ^/ never matches in per-directory context.

As a result, I changed my .htaccess file to have this...

RewriteEngine On
RewriteRule ^(.*)$ ${lc:$1}

...and it's finally working!

Suresh Kamrushi
CheckSpelling on

Matches files and directories. See the documentation for details.

Copied from = Case Insensitive URLs with mod_rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!