簡體   English   中英

如何在我的 Wordpress 網站上將非 www 重定向到 www

[英]How to redirect non-www to www on my Wordpress website

I'm trying to redirect all the requests from https://mywebsite.com to https://www.mywebsite.com (Wordpress Website).

我激活了 SSL 並使用“Really Simple SSL”插件來啟用 https。 http://www.mywebsite.com重定向到https://www.mywebsite.Z4D2366D9A2FEDA4BEC505C

但是當我寫沒有www的網站時,它就不起作用了。 我試圖在我的 .htaccess 中添加大量來自大量網站的代碼,以將非 www 重定向到 www URL 但它不起作用。 我認為在這里粘貼所有 .htaccess 配置是沒有用的,我試圖讓事情正常工作但沒有。 請幫我:(

我想你可以很容易地在谷歌上找到答案,比如https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/最后一篇文章告訴你該怎么做,將此添加到 .htaccess 的頂部(在 Wordpress 站點的根目錄中的 FTP 上找到):

RewriteEngine on
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]

(注意:確保將 www.example.com 更改為您的域。)

此外,您確定您對 .htaccess 所做的任何更改都改變了任何結果嗎? 一些托管公司要求您通過按下后端的按鈕將更改推送到 .htaccess。 否則對 .htaccess 的更改無效。

更新

好的,它在 Windows 服務器上運行與這里提到的非常相關。 .htaccess 在 Windows 服務器上不起作用。

你能試試這里提到的嗎?: IIS 將非 www 重定向到 www 和 http 到 https

所以把它放在web.config中:(不要忘記用你的網站替換zzz.com

<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

回復更新:不行。 也許我必須等待幾個小時才能產生效果? 也許我必須更改 IIS 設置中的某些內容? 那是我的 web.config 文件。

        <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="WordPress Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.mywebsitename.it/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
            </rules>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM