【问题标题】:Rewrite rule doesn't work all lowercase重写规则不能全部小写
【发布时间】:2015-04-13 10:23:44
【问题描述】:

自 3 小时以来,我一直在尝试解决这个奇怪的问题。我不敢相信。

我在 htaccess 中有“RewriteRule ^profile/([a-zA-Z0-9]+) profile.php?id=$1 [NC,L]” 我刚刚发现,如果我这样输入; www.sitename.com/Profile/1, www.sitename.com/proFile/1, www.sitename.com/profilE/1 它可以工作,但如果我输入所有小写字母,它就不起作用。这对我来说没有意义。什么会导致问题?

这都是 .htaccess 文件;

# 0 ---- Turn Rewrite engine on
RewriteEngine On

# 1 ---- Rewrite for profile.php
RewriteRule ^profile/([a-zA-Z0-9]+) profile.php?id=$1 [NC,L] 

# 2 ---- Establish a custom 404 file not found page
ErrorDocument 404 /views/404.php

# 3 ---- Redirect 403 forbidden to custom made 404 page
ErrorDocument 403 /views/404.php

# 4 ---- Prevent directory file listing in all of your folders
Options -Indexes

# 5 ---- Make pages render without their extension
Options +MultiViews

解决方案

如果要删除.php或.html扩展名并将profile.php重写为profile(同名),则必须使用这种方式删除文件扩展名。不要使用选项+多视图

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

【问题讨论】:

  • 尝试将您的 profile.php 重命名为其他名称以进行调试
  • zairwolf,是的,我刚刚发现,这就是问题所在。我不能给出相同的名字!我看了很多视频,每个人都给出了相同的名字。我不明白,为什么我的不起作用。
  • Options +MultiViews 也引起了问题。如果我删除它,我可以使用相同的名称。噗 一定有办法绕过它。我需要他们两个。我不想为了同时使用两者而奇怪地命名我的文件。

标签: php .htaccess mod-rewrite


【解决方案1】:

来自http://httpd.apache.org/docs/2.4/content-negotiation.html

MultiViews的效果如下:如果服务端接收到/some/dir/foo的请求,如果/some/dir开启了MultiViews,并且/some/dir/foo不存在,那么服务端读取目录以查找名为 foo.* 的文件,并有效地伪造一个命名所有这些文件的类型映射,为它们分配相同的媒体类型和内容编码,如果客户端按名称要求其中一个文件时将具有相同的媒体类型和内容编码。然后它会选择最符合客户要求的匹配项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-16
    • 2012-10-12
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 2013-12-20
    • 2014-10-31
    • 1970-01-01
    相关资源
    最近更新 更多