簡體   English   中英

.htaccess將所有內容重定向到https非www和404進行索引

[英].htaccess redirect everything to https non-www and 404 to index

我試圖使用.htaccess將任何請求重定向到https非www,並將每個404重定向到索引(包括以前的規則)。 這是最終結果,但不能按預期工作。 我究竟做錯了什么?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 https://mydomain.com/

您可以在.htaccess中使用以下代碼:

ErrorDocument 404 https://mydomain.com/
RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://mydomain.com%{REQUEST_URI} [L,R=301,NE]

這應該工作:

RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://mydomain.com/$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ / [R=301,L]

上面的命令會將所有非https重定向到https,然后如果文件不存在,則將其重定向到索引。

暫無
暫無

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

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