Ad

How To Redirect From Home.php To Home?

- 1 answer

This is my code in the .htaccess:

Options -Multiviews
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^home$ home.php [L]

With this code the url www.example.com/home does work but it doesn't redirect from www.example.com/home.php to www.example.com/home

With this code instead:

Options -Multiviews
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^home$ home.php [R=301,L]

I get this error:

Not Found

The requested URL /var/chroot/home/content/08/236108/html/home.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

How can I redirect from home.php to home and avoid errors ?

Ad

Answer

Options -Multiviews
Options +FollowSymlinks

RewriteEngine on
RewriteBase /

RewriteRule ^home$ home.php [L]

RewriteCond %{THE_REQUEST} home\.php
RewriteRule ^home.php$ home [R=301,L]
Ad
source: stackoverflow.com
Ad