mod 重写一个 URL,如“http://miniqr.com/http://www.anyurl.com/” (没有错别字)

发布于 2024-10-20 03:10:38 字数 1105 浏览 2 评论 0原文

好的,基本上

http://miniqr.com/http://www.anyurl.com /

(没有拼写错误)

应该调用

http://miniqr.com/api /create.php?content=http://www.anyurl.com/

为了实现这一点,我在根 .htaccess 中有这个

RewriteRule ^http:\/\/(.*)$ \/api\/create.php\?content=http:\/\/$1 [L]

重写规则 ^https:\/\/(.*)$ \/api\/create.php\?content=https:\/\/$1 [L]

可悲的是,它曾经有效,然后服务器更新了,现在它不起作用

有人知道为什么吗? (或者知道另一种方法来做到这一点)帮助会很棒

我的 .htaccess 几乎看起来像这样:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^miniqr\.com$ [NC]
RewriteRule ^(.*)$ http://miniqr.com/$1  [L,R=301]

RewriteRule ^(^$|index\.php|robots\.txt|docs|reader\/) - [L]
RewriteRule ^http:\/\/(.*)$ \/api\/create\.php\?content=http:\/\/$1  [L]
RewriteRule ^https:\/\/(.*)$ \/api\/create\.php\?content=https:\/\/$1  [L]

ok, basically

http://miniqr.com/http://www.anyurl.com/

(no typo)

should call

http://miniqr.com/api/create.php?content=http://www.anyurl.com/

to achieve this i have this in the root .htaccess

RewriteRule ^http:\/\/(.*)$
\/api\/create.php\?content=http:\/\/$1
[L]

RewriteRule ^https:\/\/(.*)$
\/api\/create.php\?content=https:\/\/$1
[L]

sad thing is, it once worked, then the server was updated, now it doesn't work

anybody knows why? (or know another way to do it) help would be awesome

my .htaccess pretty much looks like this:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^miniqr\.com$ [NC]
RewriteRule ^(.*)$ http://miniqr.com/$1  [L,R=301]

RewriteRule ^(^$|index\.php|robots\.txt|docs|reader\/) - [L]
RewriteRule ^http:\/\/(.*)$ \/api\/create\.php\?content=http:\/\/$1  [L]
RewriteRule ^https:\/\/(.*)$ \/api\/create\.php\?content=https:\/\/$1  [L]

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

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

发布评论

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

评论(2

却一份温柔 2024-10-27 03:10:38

URL 路径在 RewriteRule 看到之前进行规范化,特别是 /// 替换。您应该将规则应用于原始请求,如下所示:

RewriteCond %{REQUEST_URI} ^/(https?:.*)
RewriteRule ^ /api/create.php?content=%1 [L]

%1 引用由 RewriteCond 完成的匹配。
%{REQUEST_URI} 是 HTTP 请求第一行中的实际查询。


或者,可以不那么严格,接受方案后面的单个 / 以及 //,因为用户代理或代理可能会类似地对路径进行标准化。

The URL path is normalized before RewriteRule sees it, in particular, // is replaced by /. You should apply your rule to the original request instead like this:

RewriteCond %{REQUEST_URI} ^/(https?:.*)
RewriteRule ^ /api/create.php?content=%1 [L]

%1 refers to the match done by RewriteCond.
%{REQUEST_URI} is the actual query in the first line of the HTTP request.


Alternatively, be less strict and accept a single / after the scheme as well as //, since the path might be similarly normalized by the user agent or by proxies.

撩心不撩汉 2024-10-27 03:10:38

这不会引入重定向循环吗?:

RewriteCond %{HTTP_HOST} !^miniqr\.com$ [NC]
RewriteRule ^(.*)$ http://miniqr.com/$1  [L,R=301]

您想用它实现什么目的?

Don't this introduce a redirection loop?:

RewriteCond %{HTTP_HOST} !^miniqr\.com$ [NC]
RewriteRule ^(.*)$ http://miniqr.com/$1  [L,R=301]

What do you want to achieve with it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文