【问题标题】:apache RewriteRule prefix with wwwwww instead of wwwapache RewriteRule 前缀为 wwwwww 而不是 www
【发布时间】:2021-04-29 03:51:24
【问题描述】:

以此为例:

RewriteEngine On  
Rewritecond %{HTTP_HOST} !^www\.hslab\.nl
RewriteRule (.*) http://www.hslab.nl/$1 [R=301,L]

如果不存在www 部分,它将添加到 url。 为什么不是www,例如wwwwwww? 当我这样做时,我得到一个 404。

【问题讨论】:

  • 感谢您在问题中显示您的 htaccess 规则文件,您能否让我们更清楚地知道您在此处寻找什么?因为在将 www 添加到 url 方面,您的规则对我来说是正确的,谢谢。
  • 我想要 wwwwww 而不是 www 但后来它坏了。
  • 你在VirtualHost中配置了wwwwww吗?
  • @anubhavaI 我找不到任何可以更改它的权限。
  • 您确实需要访问VirtualHost 配置来进行设置。

标签: .htaccess url redirect mod-rewrite url-rewriting


【解决方案1】:

根据您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
##Rule when www is present in URL so add only www to url.
Rewritecond %{HTTP_HOST} ^(www)\.hslab\.nl
RewriteRule ^ http://%1%1.hslab.nl%{REQUEST_URI} [NE,R=301,L]

##Rule when www is NOT present in URL, hence add wwwwww to url as per OP
Rewritecond %{HTTP_HOST} !^www\.hslab\.nl
RewriteRule ^ http://wwwwww.hslab.nl%{REQUEST_URI} [NE,R=301,L]

【讨论】:

  • 对于那些感兴趣的人,它可以工作,但我得到的是Apache is functioning normally 而不是网站。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-10
  • 1970-01-01
  • 1970-01-01
  • 2015-04-30
  • 2014-06-28
  • 2014-09-02
  • 2015-12-29
相关资源
最近更新 更多