重定向文件夹从一个领域到另一个使用的.htaccess 301重定向重定向、文件夹、领域、htaccess

2023-09-02 09:59:52 作者:為{幸葍}努か

我试图找出一个重写,以重定向目录和它的所有文件和放大器;子目录从一个域到另一个。

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.

下面是我想实现:

olddomain.com/oldfolder / *

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]

这适用于www.olddomain.com但也为olddomain.com。什么是实现这一目标?的最佳途径 非常感谢您的帮助。

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.

推荐答案

替换您的code这一点:

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]