htacces 将停放域名页面重定向到主域名页面

发布于 2024-12-13 14:30:23 字数 665 浏览 0 评论 0原文

我遇到了一点麻烦,我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裸钻 2024-12-20 14:30:23

some_thing 不会成为 %{HTTP_HOST} 的一部分。它是 URL 其余部分的一部分。因此,您想要:

RewriteCond %{HTTP_HOST} ^www.parked.com$ [OR]
RewriteCond %{HTTP_HOST} ^parked.com$
RewriteRule ^/some_thing http://www.maindomain.com/custom_folder/some_thing [R=301,L]

另外:

  1. 确保问题中的第二个块 (some_thing -> custom_folder/some_thing) 位于 .htaccess 中的第一个块 (/ -> custom_folder) 之前 。否则,第一次重写将生效,而第二次重写将没有机会生效。

  2. 正如所写,您的第二个块有语法错误:

    RewriteCond %{HTTP_HOST} ^www.parked.com/some_thing[或]
    

    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:

RewriteCond %{HTTP_HOST} ^www.parked.com$ [OR]
RewriteCond %{HTTP_HOST} ^parked.com$
RewriteRule ^/some_thing http://www.maindomain.com/custom_folder/some_thing [R=301,L]

Also:

  1. 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.

  2. As it's written, your second block has a syntax error:

    RewriteCond %{HTTP_HOST} ^www.parked.com/some_thing[OR]
    

    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文