.htaccess Yii切换到HTTPS
我知道,切换到HTTPS与Yii无关,主要是增加.htaccess Yii切换到HTTPS,.htaccess,mod-rewrite,https,yii,.htaccess,Mod Rewrite,Https,Yii,我知道,切换到HTTPS与Yii无关,主要是增加 在.htaccess中重写规则。 现在我面临一些问题。更改.htaccess文件后 来自 到 第一个登录页面根据我的需要自动从http重定向到https,但是没有css和加载的图像我注意到这些文件的所有路径都是相对的,所以https://my.domain.de/css/print.css未找到,但http://my.domain.de/css/print.css是可访问的。如果我浏览网站css和图像中的链接,到处都会错过 有什么建议吗?重写条件
在.htaccess
中重写规则。
现在我面临一些问题。更改.htaccess
文件后
来自
到
第一个登录页面根据我的需要自动从http
重定向到https
,但是没有css
和加载的图像
我注意到这些文件的所有路径都是相对的,所以https://my.domain.de/css/print.css未找到
,但
http://my.domain.de/css/print.css
是可访问的。
如果我浏览网站css
和图像中的链接,到处都会错过
有什么建议吗?重写条件只会影响紧接着的规则。这两个-f
和-d
需要将条件应用于路由规则:重写规则。php
。否则,所有内容都会盲目地路由到index.php
,对实际存在的文件的请求将无法实现
此外,重定向需要在路由规则之前,因此您需要将条件移动到路由规则的正上方:
RewriteEngine on
# manual change the url base
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my.domain.de/$1 [R,L]
# 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
没关系,我刚找到原因。它只是在.htaccess
文件中切换位置
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my.domain.de/$1 [R,L]
# manual change the url base
RewriteBase /
# otherwise forward it to index.php
RewriteRule . index.php
RewriteEngine on
# manual change the url base
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my.domain.de/$1 [R,L]
# 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