htaccess只对根域,选定文件和所选文件夹进行重写

时间:2018-05-07 21:38:45

标签: apache .htaccess

我自己也在努力,但我认为我做错了,请建议:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\-f
RewriteRule ^folder1(.*)$ https://newdomain.com$1 [L,R=301]
RewriteRule ^folder2(.*)$ https://newdomain.com/$1 [L,R=301]
RewriteRule ^folder3(.*)$ https://newdomain.com/somefolder/$1 [L,R=301]
RewriteRule ^page1\.html https://newdomain.com/$1 [L,R=301]
RewriteRule ^page2\.html https://newdomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^/?$ https://newdomain.com/ [L,R=301]
</IfModule>

如果我请求olddomain.com的页面/文件夹不在.htaccess中,则不应重写。

有人比.htaccess有更多技能吗?

谢谢,

马克

1 个答案:

答案 0 :(得分:0)

可能你应该在newdomain

之前添加一个附加条件
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com$ [NC]