htaccess mod 重写将 http://www 更改为 http://www

发布于 2024-09-01 18:48:41 字数 658 浏览 1 评论 0原文

我想将这样的调用替换为:

www.mysite.com/sub/file.php?param1=x&param2=http://www.someurl.com

为:

www.mysite .com/sub/param1/param2

Param 1 是一个整数 Param 2 是一个 url

我在 htaccess 中编写了这个重写规则:

RewriteCond %{REQUEST_URI} \/sub\/
RewriteRule sub\/([0-9]+)\/(.*)$  sub\/file.php?param1=$2&param2=$1 [L] 

不幸的是 param2 (URL)以 http:/www.someurl.com 开头 而不是 http://www.someurl.com (注意单斜杠)。

知道是什么原因造成的吗?当我以 www.mysite.com/sub/file.php?param1=x&param2=http://www.someurl.com 格式调用具有相同参数的同一文件时,param2 确实出现好的,所以它一定是带有重写规则的东西。

I want to replace calls like this:

www.mysite.com/sub/file.php?param1=x¶m2=http://www.someurl.com

with:

www.mysite.com/sub/param1/param2

Param 1 is an integer number Param 2 is a url

I wrote this rewrite rule in htaccess:

RewriteCond %{REQUEST_URI} \/sub\/
RewriteRule sub\/([0-9]+)\/(.*)$  sub\/file.php?param1=$2¶m2=$1 [L] 

Unfortunately param2 (the URL) starts with http:/www.someurl.com instead of http://www.someurl.com (note the single slash).

Any idea what causes it? When I call the same file with same parameters in the format www.mysite.com/sub/file.php?param1=x¶m2=http://www.someurl.com , param2 does appear OK so it must be something with the rewrite rule.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2024-09-08 18:48:41

您需要从THE_REQUEST中获取值:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /sub/[0-9]+/([^?\ ]+)
RewriteRule ^sub/([0-9]+)/  sub/file.php?param1=$1¶m2=%1 [L]

You need to grab the value from THE_REQUEST:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /sub/[0-9]+/([^?\ ]+)
RewriteRule ^sub/([0-9]+)/  sub/file.php?param1=$1¶m2=%1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文