简体   繁体   English

将index.php重定向到root不适用于SSL

[英]Redirect index.php to root does not work with SSL

I'm developing a codeigniter/php web application running on AWS. 我正在开发在AWS上运行的codeigniter / php Web应用程序。 It is a LAMP stack (ubuntu). 它是一个LAMP堆栈(ubuntu)。 In order to get rid of the index.php in the url I have activated mod_rewrite and used .htaccess file to solve it. 为了摆脱URL中的index.php,我激活了mod_rewrite并使用.htaccess文件来解决它。

My .htacces file is the following (this is the entire file): 我的.htacces文件是以下文件(这是整个文件):

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] 

Everything was working fine and the url was not showing the index.php, not in the home page (http://www.example.com) and not in deeper ones such as http://www.example.com/home/index 一切正常,URL未显示index.php,不在主页(http://www.example.com)中,也未显示在更深的目录中,例如http://www.example.com/home/指数

Once I have added/configured SSL the redirect stopped working. 添加/配置SSL后,重定向将停止工作。 The home page would work just like before the SSL (https://www.example.com), however none of the deeper urls work. 主页的工作方式与SSL(https://www.example.com)之前的工作方式相同,但是更深层的URL均无效。 It is trying to open the "right" url (https://www.example.com/home/index), however the server is claiming /home/index cannot be found. 它正在尝试打开“正确的” URL(https://www.example.com/home/index),但是服务器声称找不到/ home / index。 It looks like the rewrite rule is not working correctly, since if I type https://www.example.com/index.php/home/index it works fine. 似乎重写规则无法正常工作,因为如果我输入https://www.example.com/index.php/home/index,它就可以正常工作。

I've googled and tried quite a few rewrite rules, however none of them did the magic... 我已经在Google上搜索并尝试了很多重写规则,但是它们都没有做到这一点……

An additional piece of information: I'm using the Apache 2 sites-available and sites-enabled in order to route the user to the right base url (since i'm running more than one application on my instance). 附加信息:我正在使用Apache 2站点(可用和站点启用),以便将用户路由到正确的基本url(因为我在实例上运行了多个应用程序)。

The order of files is: A.The first part of the first file is: 文件的顺序为:A.第一个文件的第一部分为:

 <VirtualHost *:80> ServerAdmin webmaster@localhost Redirect permanent / https://www.example.com/ ... </VirtualHost> 

B.The first part of the second file is: B.第二个文件的第一部分是:

 <IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin webmaster@localhost ServerName www.example.com DocumentRoot /var/www/example ... </VirtualHost> </IfModule> 

Any idea? 任何想法? I'm not sure if it is a configuration issue or something in my application. 我不确定这是配置问题还是应用程序中的问题。 Any pointer will be greatly appreciated. 任何指针将不胜感激。

Try this code in your .htacces s file. .htacces的文件中尝试此代码。 I am also developing web application on AWS with ssl enabled like you and going smoothly. 我也正在像您一样启用ssl并在AWS上顺利开发Web应用程序。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

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

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