簡體   English   中英

.htaccess強制使用https,非www並解析為索引

[英].htaccess force https, non www and parse to index

嗨,我正在與.htaccess一起制定一些規則,但是我對.htaccess的了解非常有限。 我一直在搜索,只是找到我需要的部分以及無法使之工作的地方。

當前,我使用以下規則來強制所有到index.php的鏈接:

# if requested url does not exist pass it as path info to index.php
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [QSA,L]

我的問題是將其與以下規則結合:

1. Force http -> https
 2. force www  -> non www
 3. Apply the top rules

舉個例子:
http : //wwww.example.com- > https://example.com

我希望這是有道理的; 我對mod重寫規則有很多疑問。 所以在此先感謝...

這必須添加到您的vritualhost配置中

<virtualhost *:80>   
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
    RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]   

這應該添加到您的virtualhost ssl配置中

<virtualhost *:443>
    RewriteEngine on
    RewriteRule ^$ index.php?/ [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php?/$1 [QSA,L]

這應該工作。

暫無
暫無

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

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