我如何使用与QUOT;mod-rewrite"到一个文件夹的路径重定向到一个子域,但没有一个浏览器重定向? [英] How can I use "mod rewrite" to redirect a folder path to a subdomain, but without a browser redirect?
问题描述
我有我要重定向到使用mod_rewrite一个子文件。例如,我愿意为 http://www.mydomain.com/xyz
请求重定向到子域 xyz.example.com
I have a file that I want to redirect to a subdomain using mod_rewrite. For example, I would like to redirect the request for http://www.mydomain.com/xyz
to the subdomain xyz.example.com
我不想重定向发送到浏览器,虽然(所以它不知道的页是不同的)。
I don't want to send a redirect to the browser though (so it doesn't know the page is different).
BTW。 XYZ
是一个CNAME记录指向 www.otherdomain.com。
BTW. xyz
is a CNAME record, pointing to www.otherdomain.com.
另外一个例子,只是为了澄清。如果 http://www.mydomain.com/xyz/something
输入到浏览器中,我希望Apache将返回 HTTP内容:/ /xyz.mydomain.com/something
Another example, just to clarify. If http://www.mydomain.com/xyz/something
is entered into the browser, I want Apache to return the contents of http://xyz.mydomain.com/something
推荐答案
我的 THINK 的这个会做你想让它是什么:
I THINK this will do what you want it to:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*?)/(.*?)$ http://$1.mydomain.com/$2
由于这代表它会重定向进入到子文件夹每个请求,所以如果你链接的图像或CSS,这是在一个子文件夹,它也将重写这些,如果你想列出你可以使用这个只有某些事情p>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(blog|store|other)/(.*?)$ http://$1.mydomain.com/$2
这只会重定向mydomain.com/blog/ mydomain.com/store/和mydomain.com/other /
This will only redirect mydomain.com/blog/ mydomain.com/store/ and mydomain.com/other/
这篇关于我如何使用与QUOT;mod-rewrite"到一个文件夹的路径重定向到一个子域,但没有一个浏览器重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!