Redirecting folder from one domain to another using .htaccess 301 redirect

别说谁变了你拦得住时间么 提交于 2020-01-03 03:26:09

问题


I'm trying to figure out a rewrite so as to redirect a directory and all of it's files & subdirectories from one domain to another.

Here is what I would like to achieve:

olddomain.com/oldfolder/*

to

http://newdomain.com/newfolder/*

Currently I am using the following:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule (.*) http://newdomain.com/newfolder/$1 [L,R=301]

This works for www.olddomain.com but not also for olddomain.com. What's the best way to achieve this?
Thanks so much for your help.


回答1:


Replace your code with this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^oldfolder/(.*)$ http://newdomain.com/newfolder/$1 [L,R=301,NC]


来源:https://stackoverflow.com/questions/18408416/redirecting-folder-from-one-domain-to-another-using-htaccess-301-redirect

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