【问题标题】:Redirecting not working using .htaccess file from to the main domain使用 .htaccess 文件从主域重定向不起作用
【发布时间】:2014-11-27 06:13:10
【问题描述】:

我有两个与我的主机相关联的域,第一个是具有此根的主域:public_html,第二个是具有此根的插件域:public_html/lemerge

当用户输入www.main-domain.com/lemerge 时,他访问了第二个网站。但我想将用户重定向到主网站,而不是访问第二个网站。所以如果用户输入www.main-domain.com/lemerge,用户应该被重定向到www.main-domain.com

我在 cPanel 中使用了重定向来生成此代码,但它不起作用。

RewriteCond %{HTTP_HOST} ^main-domian\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.main-domian\.com$
RewriteRule ^lemerge\/?$ "http\:\/\/main-domian\.com\/" [R=301,L]

【问题讨论】:

    标签: .htaccess mod-rewrite redirect


    【解决方案1】:

    您可以在 /lemerge/.htaccess 文件中使用此代码

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?main-domian\.com$ [NC]
    RewriteRule ^ http://%{HTTP_HOST}/ [R=301,L]
    

    【讨论】:

    • 它工作了,但你能告诉我为什么当我将代码放入 /lemerge/.htaccess 时它可以工作,但当我将它放入 public_html/.htaccess 时它不起作用?
    • 因为您可能在 root htaccess 中还有一些其他规则。此外,您的正则表达式应在目录名称后使用 .*。
    猜你喜欢
    • 2017-06-30
    • 2020-02-24
    • 1970-01-01
    • 2016-01-20
    • 2012-06-24
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多