skip to Main Content

I am using HTTPS as the primary url and as per Google SEO guidelines I have to set the following redirects

  1. http://example.com/ to https://example.com
  2. http://www.example.com/ to https://example.com
  3. https://www.example.com/ to https://example.com

The redirects which I have configured are working perfectly for homepage. However for the internal pages, only the first is working while 2nd and 3rd are adding index.php in the url.

Example

https://www.example.com/index.php/mobiles/apple/apple-iphone-se to https://example.com/index.php/mobiles/apple/apple-iphone-se

I am using the following code in .htaccess

RewriteEngine On

#Block access for libwww-perl user-agent
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]


RewriteBase /

# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]



RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^52.34.179.108
RewriteRule (.*) https://priceoye.pk/$1 [R=301,L]
  • Hosting: AWS (httpd)
  • URL: PriceOye[dot]pk

2

Answers


  1. Chosen as BEST ANSWER

    Adding the following two lines above RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC] resolved the issue

    RewriteCond %{THE_REQUEST} ^GET.*index.php [NC]
    RewriteRule (.*?)index.php/*(.*) /$1$2 [R=301,NE,L]
    

  2. create a file in your project folder named ” .htaccess ”
    then type this

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

    then go to application > config > config.php

    $config['base_url'] = 'http://localhost/project_name/';
    
    /*
    |--------------------------------------------------------------------------
    | Index File
    |--------------------------------------------------------------------------
    |
    | Typically this will be your index.php file, unless you've renamed it to
    | something else. If you are using mod_rewrite to remove the page set this
    | variable so that it is blank.
    |
    */
    $config['index_page'] = '';
    

    make it like this

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search