Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess Yii切换到HTTPS_.htaccess_Mod Rewrite_Https_Yii - Fatal编程技术网

.htaccess Yii切换到HTTPS

.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和图像中的链接,到处都会错过 有什么建议吗?重写条件

我知道,切换到HTTPS与Yii无关,主要是增加
.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