Reassign domain.tld / index.php to domain.tld (remove index.php and then 301)

I have a Magento installation and I was wondering how can I redirect domain.tld / index.php to domain.tld?

I want to delete index.php and then 301 back to root. I have a lot of old links that give me duplicate content and ugly urls, etc. An example of an old link:

domain.tld/index.php?controller=best_sales

      

In .htaccess I have the following and it doesn't work

RewriteRule .* index.php [L]

      

Thank:)


Edit:

Thank you for your answers, but I still cannot get it to work. I get 404 - Not Found when trying to make any changes.

This is my complete .htaccess, maybe there are some bugs or missing configurations that don't make it work?

Options +FollowSymLinks
RewriteEngine on    
RewriteBase /

// REMOVE HOME REWRITE FROM MAGENTO
RewriteRule ^home/?$ /? [R=301,L,NC]

// ADD WWW TO NONE WWW FOR BOTH HTTPS AND NONE HTTPS
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

// REDIRECT ALL .HTML FILES AND ALL .HTML/ FILES WITH TRAILING SLASH
RewriteRule ^google[0-9a-f]+.html$ - [L]
RewriteRule (.+)\.html$ /$1/ [L,R=301]
RewriteRule (.+)\.html\/$ /$1/ [L,R=301]

// ADD TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

// TRAILING SLASH CHECK
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

// CHECK IF REDIRECT POINTS TO A VALID FILE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

// SEND TO INDEX.PHP FOR CLEAN URLS
#RewriteRule ^(.*)$ index.php? /$1 [L,QSA]
#REWRITE EVERYTHING ELSE TO INDEX.PHP    
RewriteRule .* index.php [L]

      

+3


source to share


2 answers


Save this rule as your first rule below RewriteEngine On

to remove index.php

from your URL:



DirectoryIndex index.php

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

      

+2


source


I am assuming that without any rules, it already renders your content for domain.tld/?controller=best_unicorns

. If the url before the query string ends with "index.php", you want to redirect to that url without index.php. In fact, the part between the domain name and the query string only contains "index.php".

To do this, you need to use the R

(redirect) flag :



RewriteRule ^index\.php$ / [R,L]

      

Delete another attempt. If this rule works, change the flags to [R=301,L]

to make it permanent. This way, both browsers and search engines only know to look in one place.

0


source







All Articles