Redirect from index.php to non index.php page

Hello, @kerimsarigul

We have a journal with https://www.journal.com/index.php/journal-name

We have used the below code to remove index.php from URL

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

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

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

Also, changed restful_url to On

Now the website is accessed without index.php by default.

However, the articles page or any page, if I type index.php in the URL, it still showing index.php, meaning I can access an article with and without index.php

Using OJS OJS 3.4.0-1

Can you help with a code to redirect a page with index.php to no index.php page.

Could you check if this works?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.journal\.com [NC]
RewriteRule ^(.*)$ https://journal.com/$1 [L,R=301,NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php/(.*)$ /$1 [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Replace www.journal.com with your actual domain name

Thank you @kerimsarigul

It worked.

1 Like