htaccess how to redirect all pages, but not the root directory

你。 提交于 2019-12-31 01:28:06

问题


i need a help witch an htaccess 301 redirect.

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)

EXAMPLE:

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


回答1:


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

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]



回答2:


On www.site.com host Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

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

RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteRule ^.+$ http://www.newsite.com%{REQUEST_URI} [L,R=301]


来源:https://stackoverflow.com/questions/11999047/htaccess-how-to-redirect-all-pages-but-not-the-root-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!