Deepak Kamat
Deepak Kamat

Reputation: 1980

Magento, redirect URLs with index.php to URLs without it

I am setting up a Magento website which is not inside of any sub-directory such as /shop.

Before every URL on the website had the index.php append next to the domain name, for e.g the admin panel was example.com/index.php/admin.

I enabled Mod_rewrite in Magento's admin panel and added an .htaccess file with the following to make sure that example.com/admin actually goes to the admin panel and so on. It does work.

Here's the htaccess configuration:

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

The problem is that when I manually type example.com/index.php/admin it takes me to the admin panel as expected but the URL stays that, I expected it to redirect to the right URL which is example.com/admin but I am not able to.

Do I have to add any configurations to the htaccess or is it Magento related?

Upvotes: 1

Views: 1587

Answers (1)

mega6382
mega6382

Reputation: 9396

You can use the following rewrite rules to do this:

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

This will check if the url contains index.php and if it does then redirect to the url without index.php.

Upvotes: 3

Related Questions