2

When I try to enter my website from url www.mypage.com I got something like http://www.mypage.com/index.php/https://mypage.com/https://www.mypage.com....

When I enter from url mypage.com I got https://mypage.com - AND ITS OK

When I enter from url mypage.com/stuff I got https://mypage.com/index.php/stuff (page is working)

When I enter from url www.mypage.com/stuff I got https://mypage.com/index.php/stuff

What I should do? I would like to have always url like https://mypage.com without index.php and without 'www'.

My .htaccess :

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

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Thanks!

Ridd
  • 10,701
  • 3
  • 19
  • 20

1 Answers1

3

Try switching the order around so the internal redirect to index.php/$1 executes last:

AddHandler application/x-httpd-php70 php
RewriteEngine On

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

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Brandon Harris
  • 962
  • 7
  • 6
  • It's gives the same result – Ridd Feb 03 '16 at 11:48
  • 1
    clear browser cache and re-test. are there any other rewrites in .htaccess or main config that may be affecting the result? does the php itself do any URL manipulation or redirection? – Brandon Harris Feb 03 '16 at 17:41
  • Awesome! It's funny but clear browser cache with switching orders helps! Thank you! – Ridd Feb 05 '16 at 12:08
  • Great! Glad that worked. And yes, when testing rewrites, always good to use a clean browser session... e.g. Chrome: Incognito or IE: InPrivate..etc. That's good a habit for any web development testing. – Brandon Harris Feb 06 '16 at 01:52
  • Works for me. Could somebody shed some light on how/why this works? – ACJ Nov 27 '17 at 15:44