【发布时间】:2015-10-28 09:36:18
【问题描述】:
htaccess 文件将我的高级 Yii2 应用程序重定向到前端 index.php 文件,因为已经有一个 .htaccess 文件。其中有以下几行..
现在是我根目录下的 .HTACCESS
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
现在我搜索了互联网,如果我想重定向到 https,我发现了这个,然后我必须添加这个。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
所以我是这样添加的......
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
然后它在没有任何 js 和 css 的情况下加载网站......而且它也在 http 中。但它需要的内容应该在 https 中。
我明白这是因为我的另一个重写声明。但我在这方面不是那么专业。请提出一些建议。
这里这个东西,如果它是单独的,它可以完美地工作,没有任何问题。
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
它将我的 http 发送到 https。所以它的效果很好。
或者如果这是单独的
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
这条规则告诉从 [.htaccess Directory/frontend/web/] 目录执行 index.php 文件。表示执行 frontend/web/index.php 。这样做非常重要,因为这是按照框架结构进行的。
所以我必须将这两个规则组合在一起并构建一个适用于这两种情况的 .htaccess。
结论
所以我的 .HTACESS 应该告诉服务器我们必须在 https 中运行 [.HTACESS DIR/frontend/web/index.php]。
问题更新
这是我的 index.php 所在的 frontend/web/ 文件夹下的 .htaccess
这是在 index.php 所在的根/前端/web 文件夹中。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
我必须在这里添加 https 吗?
【问题讨论】:
-
它不会将主页重定向到https ...它停留在http ..它还调用http中的资源...但是http中不允许使用资源..它们只允许在https中.
-
@anubhava 你可以查看iklyn.com
-
是的,它正在工作......并且因为它产生了问题......可能是两个重写条件相互冲突......!!
-
@anubhava 看到这个iklyn.com url 有效...在这里它将页面重定向到我的前端应用程序..它在其他文件夹中..所以.htaccess 有效...我应用了一些错误规则...两个规则相互冲突
-
@anubhava 是的,它没有重定向到 https ...它只是将资源重定向到 https ..而不是我的 php 文件...
标签: php regex apache .htaccess mod-rewrite