how to redirect all www traffic with htaccess to e

2019-09-05 09:59发布

Question is pretty simple I guess, but I fail to do this myself.

I have a website on http://website.com and want to 301 redirect ALL requests on www.website.com to http://website.com/ but make sure all directories and filenames stay the same (so not all requests end up at the homepage).

So whatever people may type (like www.website.com/something.here) should 301 redirect to website.com/something.here

How to do this?

1条回答
Viruses.
2楼-- · 2019-09-05 10:24

Add the below to your .htaccess file. Should do the trick.

RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

This requires that the rewrite engine is on...

<IfModule mod_rewrite.c>

############################################
## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^yoursite.com
    RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

</IfModule>
查看更多
登录 后发表回答