Prince Prince - 5 months ago 11
PHP Question

URL rewriting: Change mydomain.com/index.php to mydomain.com/home

I am working with

PHP
and I want to change this url
mydomain.com/index.php
to this
mydomain.com/home
so wrote the following code:



RewriteEngine on
RewriteRule home index.php


When I go to
mydomain.com/home
it works but when I go to
mydomain.com/index.php
the url does not change to
mydomain.com/home


How can I solve this problem, please ?

Answer

Try :

RewriteEngine on
#externally redirect "/index.php" to "/home"
RewriteCond %{THE_REQUEST} /index\.php
RewriteRule ^ /home [L,R]
#internally map "/home" back to "/index.php"
RewriteRule home index.php