简体   繁体   中英

Should I use redirect 301 for htaccess

Here is the code I'm using to always add https and www to my code.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

I've read about making the redirect = 301 and was wondering if and how I should do that?

301 redirect is used for permanent URL redirection so, in your case, [R=301,L] should be used.

Google states this:

If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.

And also according to Google HTTPS directions 301 redirect is considered a best practice for HTTPS redirects.

301重定向比401更好(Google不喜欢),这很好。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM