301 redirection of all pages except the homepage

送分小仙女□ 提交于 2020-01-03 03:34:10

问题


What I'm trying to achieve is a 301 redirection of all the pages/resources for a domain except the root of the site every page then should move from www.example.com/example.com to old.example.com.

I'm not an htaccess guru but this is the solution I came up with...

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond !^$ [NC]
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]

But seems not to work


回答1:


You were missing the TestString in the RewriteCond

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]


来源:https://stackoverflow.com/questions/8994501/301-redirection-of-all-pages-except-the-homepage

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