2

At my website, I was using URL addresses such as

http://me.example.com/index.php?p=home

Then I decided to use

http://me.example.com/?p=home

It all worked automatically without any ".htaccess" file. But addresses which contain "index.php" also still work. Some sites have links to my site in "old" format. I want people to stop using this "old" format and redirect them to the "new" format URL, whenever they use "old" format. All I want to do is to remove "index.php" from URL and also change this URL in visitor's browser.

1

1 Answer 1

5

Here is the code that will go in .htaccess under DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^index\.php/?$ / [L,R=301,NC]
Sign up to request clarification or add additional context in comments.

2 Comments

how would one preserve an url path and still do this? eg example.com/folder/index.php => example.com/foler/
figured it out: RewriteRule ^(.*)?index\.php/?$ /$1 [L,R=301,NC]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.