如何设置Apache的mod_rewrite重定向所有,但一个子文件夹 [英] How to setup Apache mod_rewrite to redirect all but one subfolder

查看:217
本文介绍了如何设置Apache的mod_rewrite重定向所有,但一个子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚建立了一个新网站,并准备好从我目前的网络服务器切换到新的网络服务器。

I've just created a new website and am ready to switch from an my current webserver to a new webserver.

目前的网络服务器将被重新命名WWW2
新的Web服务器将被称为WWW

The current webserver will be renamed www2 The new webserver will be known as www

我想所有流量从WWW2到www的重定向除了的一个目录。我的目录结构是这样的:

I want to redirect all traffic from www2 to www except for one directory. My directory structure looks like this:

 /var
     /www
         /html
            index.html
            page2.html
            /orange
                 index.html
            ...
            /archive
                 index.html
                 important-page1.html
                 important-page2.html
            /turquoise
                 index.html
            ...

我想重定向一切相当于WWW页面

I would like to redirect everything to the equivalent www page

 e.g. www2.mydomain.com/orange/index.html -> www.mydomain.com/orange/index.html
 www2.mydomain.com/turquoise/index.html -> www.mydomain.com/turquoise/index.html

除非作为/存档文件夹。我想用户请求:

EXCEPT for the /archive folder. I would like users requesting :

www2.mydomain.com/archive/important-page1.html查看关于WWW2页面和不可以重定向

www2.mydomain.com/archive/important-page1.html to view the page on www2 and not be redirected.

我是否使用mod_rewrite或mod_redirect?而且我可以在httpd.conf?

Do I use mod_rewrite or mod_redirect? And can I set this up in httpd.conf?

感谢

推荐答案

是的,你需要的mod_rewrite。
尝试:

Yes, you would need mod_rewrite. Try:

RewriteEngine on
RewriteCond $1 !^archive
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

注: R = 301 301是一个的永久重定向,你需要,如果你希望它是暂时将其更改为302。

Note: The 301 in R=301 is a permanent redirect, you'll need to change it to 302 if you want it to be temporary.

这篇关于如何设置Apache的mod_rewrite重定向所有,但一个子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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