.htaccess 如何将子域中的一个文件重定向到新URL?

.htaccess 如何将子域中的一个文件重定向到新URL?,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我一直在使用.htaccess将旧网站上的URL重定向到包含旧网站文件的子域。例如,我的.htaccess文件中充满了如下规则: RewriteRule ^some-file.html$ http://subdomain.domain.com/some-file.html [NC,R=301,L] 但是,在子目录中有一个文件我想指向另一个URL。我如何才能为一个文件反转此值,并拥有http://subdomain.domain.com301重定向到http://www.domain.com/s

我一直在使用
.htaccess
将旧网站上的URL重定向到包含旧网站文件的子域。例如,我的
.htaccess
文件中充满了如下规则:

RewriteRule ^some-file.html$ http://subdomain.domain.com/some-file.html [NC,R=301,L]
但是,在子目录中有一个文件我想指向另一个URL。我如何才能为一个文件反转此值,并拥有
http://subdomain.domain.com
301重定向到
http://www.domain.com/some/directory/

编辑:这是我当前在
.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^old\.domain\.com$ [NC]
RewriteRule ^(somefile.html)/?$ http://www.domain.com/some/directory/ [L,R=302,NC]

RewriteCond %{HTTP_HOST} ^old\.domain\.com$ [NC]
RewriteRule ^(some-file.html)/?$ http://www.domain.com/some/directory/ [L,R=302,NC]

将此代码放入
subdomain.domain.com的
文档根目录下的
.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^(some-file|somefile)\.html$ http://www.domain.com/some/directory/ [L,R=302,NC]
一旦确认规则正常工作,只需将
R=302
更改为
R=301


这将重定向到
some file.html
`somefile.html
以重定向到
www.domain.com/some/directory/

谢谢!我应该在我的第一篇文章中明确这一点,但是如果旧文件是
some file.html
,并且我希望它指向
www.domain.com/some/directory/
,该怎么办?很抱歉没有澄清,但是谢谢你的帮助!谢谢我尝试了上面的编辑,但似乎不起作用。我已将当前的
.htaccess
添加到原始规则中。我已将您的两条规则合并为一条。确保上述.htaccess位于
subdomain.domain.com
$DOCUMENT\u ROOT
中。还要确保启用了mod_rewrite和.htaccess,并且没有发生其他冲突的URL重写。我现在需要注销,几个小时后再检查。非常感谢您的帮助。我会让你知道这是否有效!