javascript 如何屏蔽URL地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10217518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to mask URL address?
提问by heron
Think I have domain.com
that redirects into some.otherdomain.com
.
I don't want to show exact url some.otherdomain.com
to my sites visitors.
I need to mask my URL, so that it will look like domain.com
Any possible way? .htaccess / javascript?
认为我有domain.com
重定向到some.otherdomain.com
. 我不想some.otherdomain.com
向我的网站访问者显示确切的网址。我需要屏蔽我的 URL,以便它看起来像domain.com
任何可能的方式?.htaccess / javascript?
回答by fmgp
The best way to hide your domain is to use a reverse proxy (apache, nginx, ...) and provide rewrite rules to it.
隐藏域的最佳方法是使用反向代理(apache、nginx 等)并为其提供重写规则。
回答by Mike Christensen
Assuming domain.com
and some.otherdomain.com
are on two physically different servers, and you can't change the DNS information for any of them, you'll need to install a reverse proxy on domain.com
. You can use mod_proxy
for this. The docs are at:
假设domain.com
和some.otherdomain.com
位于两个物理上不同的服务器上,并且您无法更改其中任何一个的 DNS 信息,您需要在domain.com
. 您可以mod_proxy
为此使用。文档位于:
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
The following information is what you need to pay attention to:
以下信息是您需要注意的:
A reverse proxy, by contrast, appears to the client just like an ordinary web server. No special configuration on the client is necessary. The client makes ordinary requests for content in the name-space of the reverse proxy. The reverse proxy then decides where to send those requests, and returns the content as if it was itself the origin.
相比之下,反向代理对客户端来说就像一个普通的 Web 服务器。不需要在客户端上进行特殊配置。客户端对反向代理的命名空间中的内容进行普通请求。然后反向代理决定将这些请求发送到哪里,并返回内容,就好像它本身就是源一样。
There's an example of a reserve proxy in the docs, but you'll want something like this:
文档中有一个保留代理的例子,但你会想要这样的东西:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://some.otherdomain.com/
ProxyPassReverse / http://some.otherdomain.com/
Basically, any request that domains in will be proxied over to some.otherdomain.com
- The local web server will forward the request over, buffer the data from otherdomain.com
, then write the same data back out as if it were local data. Hope this helps!
基本上,域中的任何请求都将被代理到some.otherdomain.com
- 本地 Web 服务器将转发请求,缓冲来自 的数据otherdomain.com
,然后将相同的数据写回,就好像它是本地数据一样。希望这可以帮助!
回答by anubhava
On the Apache webserver of domain.com you have to enable:
在 domain.com 的 Apache 网络服务器上,您必须启用:
- mod_proxy
- mod_rewrite
- .htaccess
- mod_proxy
- mod_rewrite
- .htaccess
Once these requirements are completed then put this code in your .htaccess under DOCUMENT_ROOT of domain.com
:
完成这些要求后,将此代码放在 .htaccess 下的 DOCUMENT_ROOT 下domain.com
:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://some.otherdomain.com%{REQUEST_URI} [L,P]
Important flag here is P
(Proxy) which will basically make domain.com
proxy all the requests to some.otherdomain.com
without showing it in the browser. See here for more documentation on this flag: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
这里的重要标志是P
(代理),它基本上将domain.com
代理所有请求,some.otherdomain.com
而不在浏览器中显示它。有关此标志的更多文档,请参见此处:http: //httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
回答by Tobias Krogh
I always think the best way is doing such things via mod_rewrite (or similar) in the server configuration (Apache or whatever is used)
我一直认为最好的方法是通过服务器配置(Apache 或使用的任何东西)中的 mod_rewrite(或类似的)来做这些事情
回答by Mendhak
The easier way would be to set up a page on domain.com with an iframe on it and set the source of the iframe to some.otherdomain.com. However, a user will be able to view source of the page and see that your iframe is pointing to some.otherdomain.com.
更简单的方法是在 domain.com 上设置一个带有 iframe 的页面,并将 iframe 的源设置为 some.otherdomain.com。但是,用户将能够查看页面的源代码并看到您的 iframe 指向 some.otherdomain.com。
<iframe src="http://some.otherdomain.com/">...
The other option is to use a mod_rewrite in your .htaccess as shown in this thread.
另一种选择是在您的 .htaccess 中使用 mod_rewrite,如此线程所示。