htaccess redirect example.com/index.php to example

2019-09-05 05:13发布

问题:

Thanks in advance, I am trying to redirect anyone who types in example.com or example.com/index.php to example.com/home

Please let me know, I have tried the htaccess rules of redirect permanent and 301's and they have not worked. My pages are created dynamically.

回答1:

First, make sure your syntax is correct. Is this what your .htaccess file looked like?

Redirect 301 / http://example.com/home
Redirect 301 /index.php http://example.com/home

If you're sure, try this:

RewriteEngine on
RewriteBase /
RewriteRule ^& http://example.com/home [L,R=301] 
RewriteRule index.php http://example.com/home [L,R=301]


回答2:

Couldn't you just put a php script to redirect visitors? The following should work, save it as index.php in your root directory.

<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.yoursite.com/home" ); 
?>