htaccess重定向www到非www无效

3
这真的让我很头疼。出于某种原因,我的域名不能将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]

请发布您的 .htaccess 文件。 - Ed de Almeida
#强制非www: RewriteEngine on RewriteCond %{HTTP_HOST} ^www.nextoronto.com [NC] RewriteRule ^(.*)$ https://nextoronto.com/$1 [L,R=301] - WordPressDeveloper
4个回答

2

看起来很合理,也许是因为前面的规则已经生效导致它没有被触发?

以下是我使用的有效方法:

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

0
当重写无效时,不管你做什么,请考虑我遇到的问题。在我的笔记本电脑上,IIS或WAMP将所有对我的域(称其为example.com)的调用都重定向到localhost。因此,在我的example.com服务器上创建的所有重写都是徒劳的,因为没有任何对example.com的调用从我的计算机中传出。只需执行“ping example.com”,如果您得到127.0.0.1的IP,请编辑您的HOSTS文件。

0

修改URL并尝试使用以下代码:

RewriteEngine on
rewritecond %{http_host} ^www\.example\.com [nc]
rewriteCond %{SERVER_PORT} 80 
rewriterule ^(.*)$ https://example.com/$1 [r=301,nc]

0

步骤1

您应该创建像这样的.htaccess文件

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?url=$1

步骤2

进入目录,然后查看标记选项文件扩展名。然后查看.htaccess文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接