简体   繁体   中英

Redirect index.php to root does not work with SSL

I'm developing a codeigniter/php web application running on AWS. It is a LAMP stack (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.

My .htacces file is the following (this is the entire file):

 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

Once I have added/configured SSL the redirect stopped working. The home page would work just like before the SSL (https://www.example.com), however none of the deeper urls work. It is trying to open the "right" url (https://www.example.com/home/index), however the server is claiming /home/index cannot be found. 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.

I've googled and tried quite a few rewrite rules, however none of them did the magic...

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).

The order of files is: A.The first part of the first file is:

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

B.The first part of the second file is:

 <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. I am also developing web application on AWS with ssl enabled like you and going smoothly.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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