【问题标题】:How to redirect root URL to another page URL of the website via .htacess?如何通过 .htaccess 将根 URL 重定向到网站的另一个页面 URL?
【发布时间】:2021-04-08 17:25:20
【问题描述】:

如何通过 .htacess 文件将主域 URL 重定向到另一个页面?

我用过这段代码,但它不能正常工作,

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?uniqayalifestyle\.com
RewriteRule ^(.*)$ https://uniqayalifestyle.com/winter-offers/$1 [R,L]

这是我的网址:https://uniqayalifestyle.com/ 我想重定向到这里:https://uniqayalifestyle.com/winter-offers/

【问题讨论】:

  • 这些规则对我来说很好用。您能否检查一下您的 htaccess 规则是否真的被启动了。备份您当前的 htaccess 文件,然后尝试在其中放置 ---------- 类型的垃圾行,然后重新启动 apache 并查看是否出现 500 内部错误,让我知道它是怎么回事。
  • @RavinderSingh13 亲爱的先生,它不起作用,如果有其他解决方案,请告诉我。
  • 当然,是的,我正在努力提供帮助,您能按照我之前评论中的要求做吗?
  • 谁能帮帮我?
  • 抱歉,但“它不工作”不是对“看看你是否得到 500 内部错误,让我知道它是怎么回事”问题的有效答案。 @RavinderSingh13 要求你做的是在你的配置文件中实现一个明确的语法错误,以检查它是否被解释 at all 。你从来没有回答过这个问题。

标签: .htaccess redirect dns


【解决方案1】:

您是否尝试使用端口443 而不是80,因为您使用的是https

代替:

RewriteCond %{SERVER_PORT} 80

应该是:

RewriteCond %{SERVER_PORT} 443

您也可以尝试VirtualHost 级别。

以下工作并将将https://uniqayalifestyle.com/重定向到https://uniqayalifestyle.com/winter-offers/

<VirtualHost *:443>
  ServerName test.example.com
  ServerAlias example.com notthis.example.com

  RewriteEngine on
  RewriteRule   "^/$"  "/winter-offers/"  [R]
</VirtualHost>

您可以根据需要进一步自定义。

【讨论】:

    猜你喜欢
    • 2021-10-28
    • 1970-01-01
    • 2023-02-02
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多