8

index.php is not removing while i use https but it works for http. What I need to do is my site work properly such as it works on http and https both. Anybody faced same issue help me to fix this.

Ex: In http

  1. http://xyz.mydomain.com/users/login //works fine
  2. http://xyz.mydomain.com/index.php/users/login //works fine

IN https

1) https://xyz.mydomain.com/users/login // 404 page not found
2) https://xyz.mydomain.com/index.php/users/login // works fine

MY htaccess code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

config.php My base url is set as

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
10
  • why not do $config['index_page'] = ''; to remove the index.php inclusion in the first place? Commented Mar 14, 2016 at 7:23
  • first thing I'd do is check what $config['base_url'] is set to after you do all of that. something like print_r($config['base_url']); exit; Commented Mar 14, 2016 at 7:25
  • $config['index_page'] = ''; is same as you wrote Commented Mar 14, 2016 at 7:29
  • what's the output of $config['base_url'] in all 4 of your test cases? Commented Mar 14, 2016 at 7:29
  • 1
    You should check if mod_rewrite is enabled for https, also check the AllowOveride permissions . Check with your provider or system administrator. This is a server setting issue. The .htaccess is fine. You can also move the mod rewrite to the vhost.conf and ssl.conf. Commented Mar 14, 2016 at 7:36

1 Answer 1

1

Seems that there is a problem in your host file. If you are using apache, change your host file like;

<VirtualHost *:443>
   ServerAdmin [email protected]
   DocumentRoot /path
   ServerName xyz.mydomain.com
   ServerAlias www.xyz.mydomain.com

   SSLEngine On
   SSLOptions +StrictRequire
   SSLCertificateFile /path to ssl file/mydomain.crt
   SSLCertificateKeyFile /path to ssl file/mydomain.key
   SSLProtocol TLSv1
    <Directory "/path">
        Require all granted
        Options -FollowSymLinks -Includes -ExecCGI -Indexes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    RewriteEngine On
</VirtualHost>

Now chnage your htaccess file like:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   RewriteEngine On
   RewriteCond %{SERVER_PORT} 80
   RewriteRule ^(.*)$ https://xyz.mydomain.com/$1 [R=301,L]

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

Happy Coding :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @sujeet Kumar in my vhost configuration following were missing **<Directory "/path">Require all granted Options -FollowSymLinks -Includes -ExecCGI -Indexes AllowOverride All Order allow,deny Allow from all </Directory> RewriteEngine On ** its working cool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.