【问题标题】:.htaccess can't read url with %20.htaccess 无法读取带有 %20 的 url
【发布时间】:2016-09-15 07:02:53
【问题描述】:

这就是我的 htaccess 文件现在的样子:

RewriteEngine On
RewriteRule ^([\sa-zA-Z0-9_-]+)$ view.php?folder=$1
RewriteRule ^([\sa-zA-Z0-9_-]+)/$ view.php?folder=$1
RewriteRule ^([\sa-zA-Z0-9_-]+)\.html$ view.php?page=$1

它接受的网址为:

http://localhost/new.html to view.php?page=new
http://localhost/something to view.php?folder=something
http://localhost/something/ to view.php?folder=something

但它不适用于以下网址:

http://localhost/something%20else
http://localhost/something%20else/

应该是view.php?folder=something%20else

【问题讨论】:

  • 我没有收到任何错误,它显示的空白页面在 URL 中带有 %20。
  • 不,它不起作用.. http://localhost/something%20else/ 正在尝试以该名称查找目录,该目录并未传递给 view.php 本身
  • 一样,它写,没有something else这样的目录
  • 是的,我是说先生。
  • Not Found The requested URL /blank hiuz/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.Not Found The requested URL /blank hiuz/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

标签: php .htaccess


【解决方案1】:

According to this answer 你应该在你的 htaccess 重写中使用一个 url 重写标志。

(无耻引用链接:)

尝试添加B 重写标志。该标志告诉 mod_rewrite 转义 反向引用,documentation says this:

_rewrite 必须在映射 URL 之前对其进行转义,因此在应用反向引用时将对其进行转义。使用 B 标志, 反向引用中的非字母数字字符将被转义。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-03
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多