htaccess将www重定向到非www不起作用 [英] htaccess redirect for www to non-www not working

查看:65
本文介绍了htaccess将www重定向到非www不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在驱赶我香蕉。由于某些原因,我的域无法将https-WWW重定向到https-non-WWW。除了 https://www.nextoronto.com

This is driving me bananas. For some reason my domain will not work to redirect https-WWW to https-non-WWW. This works with every other permutation except https://www.nextoronto.com

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

What code do I use in the .htaccess that will allow it to work for all permutations?

编辑:现在是重写代码:

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


推荐答案

听起来不错,也许由于前面的其他规则未达到该规则?

It looks sound, perhaps that rule isn't being reached due to other rules in front of it?

这是我使用的有效的方法:

Here is what I use that works:

# 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...

这篇关于htaccess将www重定向到非www不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆