【发布时间】: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