htacces 将停放域名页面重定向到主域名页面
我遇到了一点麻烦,我的 htacces 上已经有这段代码,用于将停放的域重定向到主域上的自定义文件夹,如下所示:
RewriteCond %{HTTP_HOST} ^www.parked.com [OR]
RewriteCond %{HTTP_HOST} ^parked.com$
RewriteRule ^(.*)$ http://www.maindomain.com/custom_folder/ [R=301,L]
效果很好。
但是,我还需要将自定义文件夹/页面从停放域重定向到主域,如下所示:
www.parked.com/custom_folder -> www.maindomain.com/custom_folder/some_thing
我不能这样做。我尝试添加上面的代码,但所有内容都重定向到第一条规则:
RewriteCond %{HTTP_HOST} ^www.parked.com/some_thing[OR]
RewriteCond %{HTTP_HOST} ^parked.com/some_thing$
RewriteRule ^(.*)$ http://www.maindomain.com/custom_folder/some_thing [R=301,L]
有人能指出我正确的方向吗?谢谢
i´m in a little trouble, i already have this code on my httacces to redirect a parked domain to a custom folder on main domain, like this:
RewriteCond %{HTTP_HOST} ^www.parked.com [OR]
RewriteCond %{HTTP_HOST} ^parked.com$
RewriteRule ^(.*)$ http://www.maindomain.com/custom_folder/ [R=301,L]
That works fine.
But, i need to also redirect custom folders/pages from parked domain to main domain, like this:
www.parked.com/custom_folder -> www.maindomain.com/custom_folder/some_thing
And i can´t with that. I tried adding this above code, but everything redirects to first rule:
RewriteCond %{HTTP_HOST} ^www.parked.com/some_thing[OR]
RewriteCond %{HTTP_HOST} ^parked.com/some_thing$
RewriteRule ^(.*)$ http://www.maindomain.com/custom_folder/some_thing [R=301,L]
Could someone point me on the right direction? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
some_thing
不会成为%{HTTP_HOST}
的一部分。它是 URL 其余部分的一部分。因此,您想要:另外:
确保问题中的第二个块 (some_thing -> custom_folder/some_thing) 位于 .htaccess 中的第一个块 (/ -> custom_folder) 之前 。否则,第一次重写将生效,而第二次重写将没有机会生效。
正如所写,您的第二个块有语法错误:
some_thing
和[OR]
之间缺少一个空格,如果这确实是您的 .htaccess 文件中的内容,这将破坏条件。some_thing
won't be part of%{HTTP_HOST}
. It's part of the remainder of the URL. So instead you want:Also:
Make sure that the 2nd block in your question (some_thing -> custom_folder/some_thing) comes before the 1st block (/ -> custom_folder) in .htaccess. Otherwise the first rewrite will take effect and the 2nd won't get a chance to.
As it's written, your second block has a syntax error:
That's missing a space between
some_thing
and[OR]
, which will break the condition, if that's really what's in your .htaccess file.