htaccess 301域到新域,但子域/文件夹除外

时间:2017-07-24 09:07:47

标签: apache .htaccess redirect mod-rewrite

我需要301将一些网址重定向到他们的新家,但是客户希望他们的旧网站在archive.website.com上有效(指向website.com/archive目录)。

我尝试了以下代码,但它并未阻止archive请求被重定向。如何才能实现对archive.website.comwebsite.com/archive的任何请求转到该文件夹​​,而其他任何内容重定向到newdomain.com

RewriteEngine On
RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.co\.uk$ [NC]
RewriteCond %{THE_REQUEST} !/archive [NC]
RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [L,R=301,NE]

这是/archive文件夹

中的htaccess
RewriteOptions inherit

        # -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . index.php [L]
</IfModule>
        # -- concrete5 urls end --

        # -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . index.php [L]
</IfModule>
        # -- concrete5 urls end --

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

0 个答案:

没有答案