php – 在Yii2 .htaccess中将http重定向到https
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存在的root / frontend / web文件夹中. RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php 我必须在这里添加https的东西吗?
你root / frontend / web / .htaccess应该是这样的:
RewriteEngine on RewriteBase /frontend/web/ RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] 请记住,子目录.htaccess始终优先于父目录.htaccess. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |