mod 重写一个 URL,如“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
(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
URL 路径在
RewriteRule
看到之前进行规范化,特别是//
被/
替换。您应该将规则应用于原始请求,如下所示:%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:%1
refers to the match done byRewriteCond
.%{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.这不会引入重定向循环吗?:
您想用它实现什么目的?
Don't this introduce a redirection loop?:
What do you want to achieve with it?