【问题标题】:Redirect all the requests coming from specific domain重定向来自特定域的所有请求
【发布时间】:2018-06-04 19:15:11
【问题描述】:

我想将来自特定域的所有请求重定向到特定目录。更准确地说,我有两个不同的域,即example.comexample.tk,并且两个域都指向同一个服务器。服务器有两个不同的目录,即carsbikes。我在 root 上创建了 .htaccess 文件,但无法进行配置。我希望来自example.com 的所有请求都应该重定向到cars 目录。所有来自example.tk 的请求都应该重定向到bikes 目录。

我怎样才能成功地做到这一点?

【问题讨论】:

    标签: apache .htaccess dns


    【解决方案1】:

    此 .htaccess 文件会将 http://example.com/file.html 重定向到 http://example.com/cars/file.html 并将 http://example.tk/file.html 重定向到 http://example.tk/bikes/file.html

    Filename: .htaccess
    
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} example.com$ [NC]
    RewriteCond %{HTTP_HOST} !cars
    RewriteRule ^(.*)$ http://example.com/cars/$1 [R=301,L]
    
    RewriteCond %{HTTP_HOST} example.tk$ [NC]
    RewriteCond %{HTTP_HOST} !bikes
    RewriteRule ^(.*)$ http://example.tk/bikes/$1 [R=301,L]
    

    我觉得对你有帮助

    更多参考:here

    【讨论】:

    • 也许你的意思是RewriteCond %{REQUEST_URI} !^carsRewriteCond %{REQUEST_URI} !^bikes
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2016-04-29
    • 1970-01-01
    • 2018-11-29
    • 2013-10-21
    • 2012-09-27
    相关资源
    最近更新 更多