Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

301 Redirect is Not Working with Index File

I’m trying to 301 Redirect the Index.php to another URL

Here’s my htaccess codes

Options +FollowSymLinks
RewriteEngine on

Redirect 301 /index.php /en1

RewriteRule en1 index.php [NC]

My domain for example is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

www.mysite.com 

I want this to work as

www.mysite.com/en1 

In the URL bar its showing the new URL but browser says

The page isn’t redirecting properly

How to fix this 301 Redirect?

>Solution :

With your shown samples please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.

Options +FollowSymLinks
RewriteEngine ON
##External redirect rules here.
RewriteRule ^/?$ /en1 [R=301,L]

##Internal rewrite to index.php rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en1/?$ index.php [L]

OR If you want to write a Generic rule for rewriting each non-existing file to index.php then try following:

Options +FollowSymLinks
RewriteEngine ON
##External redirect rules here.
RewriteRule ^/?$ /en1 [R=301,L]

##Internal rewrite to index.php rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

NOTE: Use either of rules set one at a time only.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading