【问题标题】:Yii switching to HTTPSYii 切换到 HTTPS
【发布时间】:2013-08-12 14:23:58
【问题描述】:

我知道,切换到HTTPS跟Yii没有关系,主要是加 rewrite rules.htaccess。 现在我面临一些问题。在我更改了我的.htaccess 文件之后

来自

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# manual change the url base
RewriteBase /

# otherwise forward it to index.php
RewriteRule . index.php 


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

第一个登录页面自动从http 重定向到https,但没有css 和图像加载。
我注意到这些文件的所有路径都是relative,所以没有找到https://my.domain.de/css/print.css,但是
http://my.domain.de/css/print.css是可以访问的。
如果我通过网站中的链接cssimages 无处不在。

有什么建议吗?

【问题讨论】:

  • 没关系,我刚刚找到了原因。这只是在.htaccess文件中切换位置

标签: .htaccess mod-rewrite https yii


【解决方案1】:

重写条件仅影响紧随其后的规则。需要将!-f!-d 这两个条件应用于路由规则:RewriteRule . index.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

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2013-07-01
    • 2014-11-05
    • 2012-09-08
    • 2012-12-28
    相关资源
    最近更新 更多