重定向,但没有显示URL redirec :: htaccess的?重定向、URL、htaccess、redirec

2023-09-02 10:10:03 作者:佳人如梦压江山重

我需要重定向某些用户来说,可能一个子域,但我不想让他们知道,他们是在一个子域。他们应该想到他们是在主域名。 我相信,这可以通过htaccess的工作要做,但它是乱码给我。

I need to redirect some users, possibly to a subdomain, but I do not want them to know that they are in a subdomain. They should think they are in the main domain. I believe this can be done with htaccess, but it is gibberish to me.

有人可以把我扔一些骨头?

Can someone please throw me some bones?

推荐答案

当服务从不同的域的内容,而不将浏览器重定向(从而改变在地址栏中的URL)的两件事情需要做。要么有一个文件路径的决议到其他域,或反向代理必须设置(和它的pretty的容易,如果装载的mod_proxy做的)。

When serving content from a different domain without redirecting the browser (thus changing the URL in the address bar) one of two things needs to happen. Either there is a file-path resolution to the other domain, or a reverse proxy must be set up (and it's pretty easy to do if mod_proxy is loaded).

看起来你有你的子域的主域名,这意味着此选项将是可行的文档根目录中。所以,如果你想它,所以当有人在他们的地址栏中把这个URL, http://domain.com/page ,他们得到供应的 http://sub.domain.com/another-page ,你会简单地添加这些规则的顶部

It looks like you have your subdomain inside the document root of your main domain, which means this option will be viable. So if you want to it so when someone puts this URL in their address bar, http://domain.com/page, they get served the content in http://sub.domain.com/another-page, you'd simply add these rules to the top of the htaccess file in the document root of your main domain (public_html):

RewriteEngine On
RewriteRule ^page(.*)$ /subdomain_folder/another-page$1 [L]

否则,第二个选择是使用的mod_proxy:

Otherwise, the second option is to use mod_proxy:

RewriteEngine On
RewriteRule ^page(.*)$ http://sub.domain.com/another-page$1 [L,P]

编辑:

我希望重定向一些用户,这取决于它们的ip(地理位置)到另一个子域。是的的public_html为根

I want to redirect some users, depending on their ip (geographic location) to another subdomain. And yes public_html is the root

您可以通过%对证的IP {REMOTE_ADDR} 变量:

RewriteCond %{REMOTE_ADDR} ^123.45.67.89$
RewriteCond !^/subdomain_folder
RewriteRule ^(.*)$ /subdomain_folder/$1 [L]