简体   繁体   English

htaccess PHP MVC重定向到https

[英]htaccess PHP MVC Redirect to https

I have a problem with my htacess file. 我的htacess文件有问题。

I have a php mvc system set up with the root looking like public [folder] application [folder] htaccess 我有一个php mvc系统,其根目录看起来像公共[文件夹]应用程序[文件夹] htaccess

The first htaccess reads 第一个htaccess读取

RewriteEngine on 

RewriteRule ^$ public/ [L]

RewriteRule (.*) public/$1 [L]

This is to remove public from the url i assume ? 这是从我假设的网址中删除public?

The second htaccess file i have is in the public directory with the index.php file which starts the php app 我拥有的第二个htaccess文件位于带有index.php文件的公共目录中,该文件启动了php应用程序

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^/public) /$1 [L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

This has been written to force the url to go to https rather than http, The problem im having is if the url is typed into the url bar as http://example.com and the rewrite happens it will take me to https://example.com/public , I am trying to remove the public directory from the url if this happens, Any help would be much apreciated. 这样做是为了强制将网址转到https而不是http,问题是如果将网址以http://example.com的形式输入到网址栏中,并且重写发生,它将带我到https:/ /example.com/public ,如果发生这种情况,我正在尝试从url中删除公共目录,将不胜感激。

Cheers Ryan 干杯瑞安

Rewrites doesn't remove parts or change the URL in the users browser. 重写不会删除部分内容或更改用户浏览器中的URL。

The first htaccess simply makes all requests to / load files from the /public -folder internally, without the user noticing. 第一htaccess的只是使所有的请求/从负载文件/public内部-folder,无需用户干预。

If you don't want /public to be available, you should change the document root to point to the public folder instead of the folder above. 如果您不希望/public可用,则应将文档根目录更改为指向公用文件夹而不是上面的文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM