从域中删除 www 的方法是什么 - htaccess 也无济于事

What is the way to remove www from a domain - htaccess is not helping too

我的 SSL 只覆盖 swellnomore.com,不覆盖 www.swellnomore.com.

我在键入 https://www.swellnomore.com. Can this be fixed (forwarded to https://swellnomore.com 时遇到安全错误?

我曾尝试将以下内容放入 htacess,但也没有帮助

# Override GoDaddy defaults that inhibit URL rewriting
Options -MultiViews
rewriteEngine On

# Rewrite URLs to remove www from domain name
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]

在放上面之前,htaccess 看起来像这样

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]

RewriteEngine On
RewriteBase /
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteCond %{HTTP_HOST} ^swellnomore.com$
RewriteRule ^/?$ "https\:\/\/swellnomore\.com\/" [R=301,L]

P.S ,我已经将站点域更改为 https://swellnomore.com 在 wp 仪表板 > 常规设置中。

如果重写域,则应重写为 https 而不是 http
试试这个重写规则:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

整个 htaccess 文件

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/ [R,L] 

</IfModule>

# END WordPress 

是的,这是可能的。您只需要将此 .htaccess 放在您的根文件夹中即可:

RewriteEngine On
RewriteBase /
RewriteRule ^/?$ http://sub.domain.com/this [L]

试试这个 javascript

 <script type='text/javascript'>
      if(history.replaceState) history.replaceState({}, "", "/");
      </script>  

注意:其中 / 是您要显示的路径。

它显示 url 就像 mysite.com 无论我点击了哪个 link。但是我在将带有查询字符串 blink 的完整 url 重新加载到地址栏的页面时遇到此代码的问题。

更新

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

示例:http://www.addondomain.com/projects/a/gallery/4/2 -> http://addondomain.com/projects/a/gallery/4/2

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

也许这会对你有所帮助:

将此添加到您的 .htaccess

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