htaccess的如何重定向所有页面,但是不是根目录 [英] htaccess how to redirect all pages, but not the root directory

查看:230
本文介绍了htaccess的如何重定向所有页面,但是不是根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助巫婆的htaccess的301重定向。

i need a help witch an htaccess 301 redirect.

我有一个网站www.site.com,但我需要改变所有网页www.newsite.com但我想不动www.site.com(对于网页信息)

I have a site www.site.com but i need to change all pages to www.newsite.com but i want not move www.site.com (for a pages information)

例如:

www.site.com (not move) index of to put then a template or message

www.site.com/2012/08/page.html move to www.newsite.com/2012/08/page.html
www.site.com/tag/keyword/ move to www.newsite.com/tag/keyword/
www.site.com/category/general/ move to www.newite.com/category/general/

我怎么能做到这一点?谢谢

how i can do that? Thanks

推荐答案

您可以尝试使用mod_alias中' RedirectMatch 来迫使东西的URI重定向。在site.com的文档根目录htaccess文件,添加:

You could try using mod_alias' RedirectMatch to force something in the URI for the redirect. In the htaccess file in site.com's document root, add:

RedirectMatch 301 ^/(.+)$ http://www.newsite.com/$1

这将使它所以任何在 http://www.site.com/ 将被重定向,而只是 HTTP:// WWW .site.com / 不会。然而, http://www.site.com/index.html 将会的重定向。如果这是一个问题,您可以使用mod_rewrite:

This will make it so anything after http://www.site.com/ will get redirected, but just http://www.site.com/ will not. However, http://www.site.com/index.html will get redirected. If that's an issue, you can use mod_rewrite:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.html$
# and whatever else you don't want redirected
RewriteRule ^(.*)$ http://www.newsite.com/$1 [L,R=301]

这篇关于htaccess的如何重定向所有页面,但是不是根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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