我在域上存在多年(10+)的网站,现在正在将网站从一个CMS更改为另一个。移动内容是一个漫长的过程,其中一些内容不会移动,并且应该在未来的几年内共存。
我已将旧网站从根目录(www.example.com)移至子文件夹(www.example.com/_old)。旧网站有以下.htaccess强制www。在我的域名自2007年初以来。我已在(www.example.com/_old/)文件夹中的.htaccess上删除了此内容。
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
现在我在另一个子目录(www.example.com/dp/)中说新闻网站,只用.htaccess和重写保持根空,但我真正想要的是:
我在这里:
RewriteCond %{HTTP_HOST} www.example.com
RewriteRule ^(.*)$ /_old/$1 [L,R=301]
RewriteCond %{HTTP_HOST} example.com
RewriteCond %{REQUEST_URI} /dp/
RewriteRule ^(.*)$ http://example.com/$1 [L,R=307]
RewriteCond %{HTTP_HOST} example.com
RewriteRule ^(.*)$ http://www.example.com/_old/$1 [L,R=301]
这仍然是子网站/ dp /
中的新网站答案 0 :(得分:0)
#if file or directory doesn't exist, check the _old directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/_old
RewriteRule .* /_old/$0 [L]
#note that I omitted the redirect flag. That way the old url just work like they used to. If you really want you can just add them, but please, just give it a try. This might even fix problem nr. 3
# remove www. from everything except _old urls
RewriteCond %{HTTP_HOST} www\.example\.com
RewriteCond %{REQUEST_URI} !/_old
RewriteRule ^(.*)$ http://example.com/$1 [L,R=307]
只是为了澄清一点。如果内部重写到/_old/seafood.html,用户请求www.example.com/seafood.html之类的旧链接。如果将来您想为此创建新页面,只需在根目录中创建seafood.html。此文件将自动优先于/ _old文件夹中的相同文件名。