【问题标题】:htaccess redirect with complete urlhtaccess 重定向与完整的 url
【发布时间】:2019-04-17 19:19:59
【问题描述】:

我有两个需要重定向的链接:

https://mywebsite.com/countries
https://mywebsite.com.ar/countries

这两个链接都需要重定向到另一个页面。

我知道我可以在我的 .htaccess 中这样做,但两个链接都以 /countries 结尾:

重定向 301 /国家 http://mynewurl.com/countries

是否可以检查我要重定向的整个路径或至少.com.ar 并在我的.htaccess 中设置这些差异

我也试过了,但似乎不能正常工作:

RewriteCond %{HTTP_HOST} =mywebsite.com.ar/countries
RewriteRule (.*) https://mynewurl.com.ar/countries/$1 [R,L]

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} mywebsite\.(com\.ar)$ [NC]
    RewriteRule ^countries(/.*)?$ https://mynewurl.%1/$0 [R=301,NE,L]
    

    确保使用新浏览器来测试此更改。

    【讨论】:

    • 对不起,我不明白,这如何根据 (.com) 或 (.ar) 重定向到它们的相关页面。
    • 不,https://mywebsite.com/countries 将重定向到 http://mynewurl.com/countrieshttps://mywebsite.com.ar/countries 将重定向到 http://mynewurl.com.ar/countries
    • 希望它现在有效。否则告诉我你得到了什么错误的重定向 URL 以及预期的结果?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-08
    • 2016-08-21
    • 2023-03-25
    • 2016-12-20
    • 2022-11-16
    • 1970-01-01
    相关资源
    最近更新 更多