重写规则以透明方式重定向到子文件夹 [英] Rewrite Rule for Redirecting Transparently to Subfolder

查看:73
本文介绍了重写规则以透明方式重定向到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为apache编写一个重写规则,以便将诸如http://www.domain.com/subfolder1的请求重定向到http://www.domain.com/subfolder2. 这应该是透明发生的(即:在浏览器中无需更改网址),并且所有后续的网址请求或链接都应重定向到新的子文件夹(subfolder2). 这有可能吗?

I wish to write a rewrite rule for apache so that a request such as http://www.domain.com/subfolder1 would redirect to http://www.domain.com/subfolder2. This should happen transparently (i.e: without the url changing in the browser) and all subsequent url requests or links should be redirected to the new subfolder (subfolder2). Is this possible and how?

当前,我有此重写规则,该规则确实重定向到subfolder2,但是通过单击任何链接,所有请求都将转发到根路径.即www.domain.com.例如,当我打开此URL(www.domain.com/subfolder1)时,指向link.php的任何链接都重定向到www.domain.com/link.php,而应转到www.domain.com/subfolder2/link.php.

Currently I have this rewrite rule which does redirect to subfolder2 but by clicking any link all requests are forwarded to the root path. i.e. www.domain.com. e.g Any link that points to link.php when I have this url (www.domain.com/subfolder1) open is redirected to www.domain.com/link.php while it should go to www.domain.com/subfolder2/link.php.

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent


Options -Indexes
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^subfolder1?$ /subfolder2/ [P,L]

推荐答案

用以下代码替换代码:

Options +FollowSymLinks -MultiViews -Indexes
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^subfolder1(/.*|)$ /subfolder2$1 [NC,L]

这篇关于重写规则以透明方式重定向到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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