【问题标题】:htacess URL rewriter not working on my hostinghtaccess URL 重写在我的主机上不起作用
【发布时间】:2020-12-29 17:13:28
【问题描述】:

我正在尝试将我的 URL http://windllfiles.com/dlldata.php?name=All.dll 更改为 http://windllfiles.com/All.dll/http://windllfiles.com/?character=B 更改为 http://windllfiles.com/character/B/

我正在尝试将 http://windllfiles.com/dlldata.php?name=All.dll 的重定向 URL 写为

 Options +FollowSymLinks
RewriteEngine on
RewriteRule dlldata/name/(.*)/ dlldata.php?name=$1
RewriteRule dlldata/name/(.*) dlldata.php?name=$1

对于http://windllfiles.com/?character=B as

Options +FollowSymLinks
RewriteEngine on
RewriteRule /character/(.*)/ ?character=$1
RewriteRule /character/(.*) ?character=$1

但两者都不起作用

【问题讨论】:

  • . 包含/。使用[^/]+,因为它不是正斜杠。您也可以使用/? 使斜杠成为可选的,那么您只需要1 条重写规则。能否请您更新完整的.htaccess。 RewriteEngine on 不应出现两次,多个规则可能会发生冲突
  • 好像问题也写反了,http://windllfiles.com/character/B/ -> http://windllfiles.com/?character=Bhttp://windllfiles.com/All.dll/ -> http://windllfiles.com/dlldata.php?name=All.dll,对吧?
  • 你能解释一下吗?
  • 哪一部分? . 表示任何单个字符。 / 符合该规则。
  • 根据this meta postthis meta post,这个问题对于SO 来说根本不是题外话,所以近距离投票是错误的。这已经被反复讨论过,并且已经确定大多数重写规则是由 Web 应用程序/框架的开发人员创建和维护的。

标签: regex .htaccess mod-rewrite


【解决方案1】:

您能否尝试使用所示示例进行以下、编写和测试。请确保在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteRule ^(All\.dll)/?$ dlldata.php?$1 [L]
RewriteRule ^(character)/(B)/?$ ?$1=$2 [L]

第一条规则将从 All.dll 开始的 url 重写为 dlldata.php?$1 其中 $1 是第一个反向引用值。第二条规则适用于从字符/B 开始的 uri,然后将它们重写为 ?$1=$2。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-10-31
  • 2012-05-03
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 2015-02-03
  • 2014-08-08
相关资源
最近更新 更多