![](/img/trans.png)
[英]Redirecting from http to https using htaccess except for certain subdirectories
[英]Not redirecting from http to https automatically using .htaccess
嘗試將我的網站從http重定向到https,但它無效......網站在http和https上打開。
這是我目前在我的htaccess文件中使用的代碼部分,但是此代碼不會使用https自動重定向網站,並使用http和https打開網站。 這讓人很困惑。
------------------------------------------------
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^www\.surffares\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/www\.surffares\.com\/" [R=301,L]
------------------------------------------------------------------------
但是這段代碼不起作用......
這是代碼godaddy建議在htaccess中使用自動重定向,但此代碼只加載首頁,自動重定向首頁但沒有其他頁面打開,當我點擊任何其他頁面時,它顯示我找不到錯誤。
---------------------------------------------------------------------
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]
--------------------------------------------------------------------
Godaddy客戶支持告訴您需要在.htaccess中提取內頁。
我如何自動將我的網站從http重定向到https,並拉出網站的所有內頁。
注意:我的網站是在php mvc laravel
我已經快速構建了一個配置來測試這個場景。 在Apache VirtualHost中,您需要確保apache使用AllowOverride遵守htaccess文件。
以下是VirtualHost中的配置:
<VirtualHost *:80>
ServerName test.com
DocumentRoot /var/www
<Directory "/var/www>
Require all granted
AllowOverride all
</Directory
</VirtualHost>
然后,在/var/www/.htaccess中,定義以下內容:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
希望有所幫助。
喬
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.