linux - htaccess 将 www 重定向到非 www 不工作

标签 linux wordpress .htaccess redirect url-rewriting

这让我发疯。出于某种原因,我的域无法将 https-WWW 重定向到 https-non-WWW。这适用于所有其他排列,除了 https://www.nextoronto.com

我在 .htaccess 中使用什么代码可以让它适用于所有排列?

编辑:这是现在重写的代码:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.nextoronto\.com [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [L,R=301]

最佳答案

看起来不错,也许由于它前面的其他规则而没有达到该规则?

这是我使用的有效方法:

# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]

# My other rewrites for routing all requests to index.php go here...

关于linux - htaccess 将 www 重定向到非 www 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36274893/

相关文章:

c - 写入()调用失败 : No space left on device: ENOSPC handling

linux - linux shell 中的特殊字符

css - 处理阿拉伯语站点的 LTR 和 RTL(国际化)

css - 屏幕调整大小时,Wordpress 主题自定义 css 不起作用

php - Htaccess 和水印

regex - 使用 .htaccess 将桌面用户从移动站点重定向

linux - 为什么在编写守护进程时需要关闭标准输入/输出/错误?

c++ - g++ Bash For Windows 和 Ubuntu 的区别

javascript - 需要来自存储在 Woocommerce 订单中的选择字段的选项文本

.htaccess - 为什么 www.mywebsite.com/folder 可以工作,但 www.mywebsite.com/folder/却不行?