301 htaccess redirect on homepage only

Edited: To better explain what I want.

We want to move our home page http://www.example.com

to a sub-page http://www.example.com/sub-page


So, in order to keep our SEO ranking, we need to write 301 Permanently Moved. And we would like the subpage url to be displayed in the browser. This should displayhttp://www.example.com/sub-page/

So the result will be if you try to enter http://www.example.com

your URL will be rewritten http://www.example.com/sub-page/

with a 301 redirect.

But every other page shouldn't be redirected! For example. http://www.example.com/contact/

should be the same.

And it also has to take care of all variations of the root domain. With and without forward slashes ( example.com

/ vs example.com

) With and without www ( www.example.com

vs example.com



source to share

2 answers

1. Enable mod_rewrite and .htaccess. 
2. Create and deploy your new home page as `/sub-page`
3. Then put this code in your .htaccess file under DOCUMENT_ROOT:


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

# reqest to example.com/ will be forwarded to example.com/sub-page
RewriteRule ^$ sub-page [L,R=301]





^/|/index.html|/index.php$     /sub-page


add the font page as you like.
^ represent the head line.
$ represent the end of the line.



All Articles