阿帕奇重写规则 - prevent重写URL出现在浏览器地址栏 [英] Apache rewrite rule - prevent rewritten URL appearing in browser URL bar

查看:210
本文介绍了阿帕奇重写规则 - prevent重写URL出现在浏览器地址栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在寻找一个特定URI重写规则。当特定的URL匹配它与适当的文件路径重写它,因此所需的内容都可以找到。然后,它改变了协议HTTPS,并允许该请求通过。

我有两个问题;


  1. 我不希望重写的路径出现在用户的浏览器 - 我要保持虚荣网址

  2. 我确实想HTTPS协议出现指示,他们是通过安全连接如访问网站的用户。

我已经尝试了几个选项,但没有成功。如果我包括[R]标志的URL和协议保持不变,但是这不是所期望的效果

我如何能做到这一点有什么建议?

这是我的规则;

  RewriteMap指令redirectsIfSecure TXT:/myserver/content/secure_urls.txt
的RewriteCond $ {小写:%{REQUEST_URI}} ^ /(+)$
的RewriteCond $ {redirectsIfSecure:%1 | NOT_FOUND}!NOT_FOUND
重写规则^ $ HTTPS(*)://myserver.com$ {redirectsIfSecure:%1} [PT]


解决方案

从mod_rewrite的文档:


  

如果指定一个绝对的URL,的mod_rewrite 检查,看有无
  主机当前的主机相匹配。如果确实如此,该方案和主机名
  被剥离出来,所得到的路径将被视为一个网址路径。
  否则,外部重定向指定网址进行。至
  强制外部重定向回当前主机,请参阅[R]标志
  下文。


如果你改写到一个完全合格的URL请求(也就是,任何事情首先是的http:// 的https:// 等),不符合你的服务器名称,那么的mod_rewrite 会发出一个HTTP重定向,这将导致在客户端浏览器从所述新的位置请求的资源。

如果你不试图之间切换HTTP和HTTPS可以使用代理规则(即 P 标志)让Apache将代表客户端的请求并返回结果,从而掩盖重写URL。

不过,如果你想从http升级到HTTPS(或其他方式),这会的总是的要求客户端重定向。

I have a rewrite rule which is looking for a particular URI. When it matches the particular URL it rewrites it with a proper file path so the required content can be found. It then changes the protocol to HTTPS and allows the request to pass through.

I have two problems;

  1. I don't want the rewritten path to appear in the users browser - i want to maintain the vanity url
  2. I do want the HTTPS protocol to appear indicating to the user that they are accessing the site over a secured conection.

I have tried a couple of options but no success. If i include the [R] flag the URL and protocol remain unchanged but that is not the desired effect

Any suggestions on how i can achieve this?

This is my rule;

RewriteMap redirectsIfSecure txt:/myserver/content/secure_urls.txt
RewriteCond ${lowercase:%{REQUEST_URI}} ^/(.+)$
RewriteCond ${redirectsIfSecure:%1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)$ https://myserver.com${redirectsIfSecure:%1} [PT]

解决方案

From the mod_rewrite documentation:

If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.

If you rewrite the request to a fully qualified URL (that is, anything starting with http://, https://, etc) that doesn't match your ServerName, then mod_rewrite will issue an HTTP redirect, which will cause the client browser to request the resource from the new location.

If you're not trying to switch between http and https you can use a proxy rule (the P flag) to have Apache make the request on behalf of the client and return the result, thus masking the rewritten URL.

However, if you're trying to upgrade from http to https (or the other way around), this will always require a client redirect.

这篇关于阿帕奇重写规则 - prevent重写URL出现在浏览器地址栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆