yii2框架的advance版,框架開啟了URL美化:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules'=>[
"<controller:\w+>/<id:\d+>"=>"<controller>/view",
"<controller:\w+>/<action:\w+>"=>"<controller>/<action>"
],
],
使用的apache服務(wù)器,項目backend目錄的web下配置.htaccess:
原來的配置是http訪問的方式,可以正常訪問:
Options +FollowSymlinks
IndexIgnore */*
RewriteEngine On
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule \.svn\/ /404.html
RewriteRule \.git\/ /404.html
加了阿里云的免費ssl證書后,修改為如下后訪問跳轉(zhuǎn)到https了卻是404:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
**ssl證書配置是:**
Listen 443
<VirtualHost *:443>
DocumentRoot "C:\WWW\demo1\backend\web"
ServerName test.ssl1.com
ServerAlias test.ssl1.com
<Directory "C:\WWW\demo1\backend\web">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
SSLCertificateFile "C:\Program Files\Apache\cert\ssl1\public.pem"
SSLCertificateKeyFile "C:\Program Files\Apache\cert\ssl1\214389064350038.key"
SSLCertificateChainFile "C:\Program Files\Apache\cert\ssl1\chain.pem"
</VirtualHost>
網(wǎng)上找了好多資料,求教各位大神怎么解決,不勝感激
web目錄下的.htaccsee完整配置,不論是一級域名還是二級域名都可以訪問,已經(jīng)經(jīng)過測試:
Options +FollowSymlinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule \.svn\/ /404.html
RewriteRule \.git\/ /404.html
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]
以下補充
實現(xiàn)http
轉(zhuǎn)https
原理就是
原先訪問80端口的轉(zhuǎn)443端口(也可以是其他端口,這個看你)
代碼角度就是
http://uri
/*變成下面*/
https://uri
這個可以基于服務(wù)器的重定向功能
你的服務(wù)器是apache的
以下的內(nèi)容都是基于apache說明的
1首先必須開啟重寫規(guī)則這個模塊LoadModule rewrite_module modules/mod_rewrite.so
2寫規(guī)則
所有重定向內(nèi)容從RewriteEngine On
開始看.
但是有一點,規(guī)則可以寫在apache
的httpd文件,.htaccess
這個實現(xiàn) 是基于httpd文件中 AllowOverride
的值 設(shè)置允許下才生效,重寫功能實現(xiàn)相當(dāng)于http文件的一個快捷方式,可以這么粗糙理解
這個是apache加載規(guī)則一個原理圖
apache加載第一個規(guī)則后
RewriteRule '正則匹配到內(nèi)容' '替換后uri' //這種格式
如果有 RewriteCond //相當(dāng)于進入一層if判斷
至此完成一個規(guī)則加載,獲得替換后的uri 作為值 進入下一規(guī)則匹配
實現(xiàn)http轉(zhuǎn)的https的規(guī)則代碼就這么點,代碼一開始已經(jīng)貼出來了.
你之所以不能生效在你的服務(wù)器上,是因為其他規(guī)則干擾.
這是你可以找下你apache/log文件.看看錯在哪里
可以在開發(fā)模式中,你自己模擬下LogLevel alert rewrite:trace等級
將這個等級調(diào)高點,生產(chǎn)模式的話則不要這么做不然會產(chǎn)生大量日志
然后在日志中分析,調(diào)整你規(guī)則位置 和匹配代碼
下面我示范下我的
其中我把等級調(diào)為8,可以看到整個規(guī)則匹配的走向流程
最后說一點,遇到翻官網(wǎng)文檔是最齊全的,別人寫的也是基于官網(wǎng)修改的,
至于語言障礙,你可以用谷歌翻譯下
在補充一點httpd文件修改必須重啟apache
而.htaccess
修改不需要
還有瀏覽器會緩存你的重定向,這是你要試試其他url參數(shù).
ps:有可能你寫對了,但是讀取了上一次的,這點我被坑過很慘T_T
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。