简体   繁体   中英

How can I redirect my 'http' URLs to my new 'https' URL (Redirect 301)?

I have installed an SSL Certificate on my hosting, for my wordpress site.

How can I redirect my old 'http' URL to my new 'https' URL, through the use of the .htaccess file, with minimum effect on my SEO Rankings?

The first option is to configure your website to work via HTTPS instead of HTTP. By default, WordPress is redirecting all of other links to the default protocol(in your case HTTPS).

You can configure it via WP-Cli. The command you need is:

wp search-replace 'OLD-URL' 'NEW-URL' --precise --recurse-objects --all-tables-with-prefix

You may check the following tutorial for more information: https://developer.wordpress.org/cli/commands/search-replace/

Another option is to set the 301 redirects in the .htaccess. I am using the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Additional information on these types of moves from Google can be found at: https://support.google.com/webmasters/answer/6033049?hl=en&ref_topic=6033084

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