简体   繁体   English

htaccess 将 www 重定向到非 www 不起作用

[英]htaccess redirect for www to non-www not working

This is driving me bananas.这让我抓狂。 For some reason my domain will not work to redirect https-WWW to https-non-WWW.出于某种原因,我的域无法将 https-WWW 重定向到 https-non-WWW。 This works with every other permutation except https://www.nextoronto.com这适用于除https://www.nextoronto.com之外的所有其他排列

What code do I use in the .htaccess that will allow it to work for all permutations?我在 .htaccess 中使用什么代码才能让它适用于所有排列?

Edit: This is the rewrite code now:编辑:这是现在的重写代码:

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

Edit the URL and try with this code:编辑 URL 并尝试使用以下代码:

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

Step 1第1步

You should make .htaccess file like this你应该像这样制作 .htaccess 文件

RewriteEngine On重写引擎开启

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?url=$1重写规则 ^(.*)$ index.php?url=$1

Step 2第2步

Go to the directory, then view mark the option file extension.转到目录,然后查看标记选项文件扩展名。 Then see the .htaccess file.然后查看 .htaccess 文件。

When no rewrite works, no matter what you do, consider what happened to me.当没有重写工作时,无论您做什么,请考虑发生在我身上的事情。 IIS or WAMP, on my laptop, redirected all calls to my domain (call it example.com) to localhost.我的笔记本电脑上的 IIS 或 WAMP 将所有对我的域(称为 example.com)的调用重定向到 localhost。 So creating all the rewrites on my example.com server were to no avail because no calls to example.com ever made it out of my computer.因此,在我的 example.com 服务器上创建所有重写都无济于事,因为我的计算机上从未调用过 example.com。 Just do a "ping example.com" and if you get an IP of 127.0.0.1, edit your HOSTS file.只需执行“ping example.com”,如果您获得 127.0.0.1 的 IP,请编辑您的 HOSTS 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM