从 .htaccess 中的 URL 中删除 http (mod_rewrite)
多年来一直坚持这个问题并尝试了很多修复,但就是无法理解它!
我运行一个网站,其中页面内容是根据 URL 生成的。例如:
http://www.mysite.com/http://www.supercheese.com
将生成 mysite.com 和 supercheese.com 内容的混搭
我为此使用的 .htaccess(在 mysite.com)是:
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule assets/.* - [L]
RewriteRule ^(.*)$ test.php?url=$1 [NC,L]
</ifModule>
所以基本上第二个 URL 是在 php 字符串中传递的。
从地址中删除 http://。
我的问题是这样的,我需要使用 .htaccess E.G 如果有人输入:
http://www.mysite.com/http://www.supercheese.com
我需要它变成:
http://www.mysite.com/www.supercheese.com
提前非常感谢您查看此内容。你们摇滚。
Been stuck on this for ages and tried loads of fixes but just can't get my head around it!
I run a site where the content of the pages are generated based upon a URL. For example:
http://www.mysite.com/http://www.supercheese.com
Would generate a mashup of content from mysite.com and supercheese.com
The .htaccess i use for this (at mysite.com) is:
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule assets/.* - [L]
RewriteRule ^(.*)$ test.php?url=$1 [NC,L]
</ifModule>
So basically the second URL is passed in a php string.
My question is this, I need to remove the http:// from the address using .htaccess
E.G. If someone types:
http://www.mysite.com/http://www.supercheese.com
I need it to become:
http://www.mysite.com/www.supercheese.com
Many thanks in advance for taking a look at this. You guys rock.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需使用
RedirectMatch
http:// httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectmatch
尝试使用:
编辑:您必须在重写规则之前将其放在
编辑:在http之前添加
/
编辑:David是的,看看他的答案并改变你写这些网址的方式
You can simply use a
RedirectMatch
http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectmatch
Try with :
Edit : you have to put this before rewrite rules
Edit : add
/
before httpEdit : David is right, take a look a his answer and change your way of writing these urls
在我看来,url 方案本质上是有问题的。
在 url 中使用未编码的冒号
:
- 除了遵循http
来指定访问协议 - 似乎会让服务器认为它正在对表单进行身份验证http://用户名:密码@主机名/
。我知道它并不能直接回答问题,解决方案是更改 url-scheme。 ;-(
It looks to me like the url scheme is inherently problematic.
Using an unencoded colon
:
in the url - other than following thehttp
to specify the access protocol - seems to make the server think that it is doing authentication of the formhttp://username:password@hostname/
.I know it doesn't directly answer the question, the solution is to change the url-scheme. ;-(