最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

htaccess - Redirect from https to http or from http to https?

programmeradmin0浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

We have a WordPress blog, google is indexing http as well as https urls. Now we are considering to either redirect https to http, or to use https and redirect all http traffic there. And how can we make all necessary changes to our WordPress installation?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

We have a WordPress blog, google is indexing http as well as https urls. Now we are considering to either redirect https to http, or to use https and redirect all http traffic there. And how can we make all necessary changes to our WordPress installation?

Share Improve this question edited May 17, 2019 at 21:33 Nicolai Grossherr 18.9k8 gold badges64 silver badges109 bronze badges asked Apr 30, 2019 at 5:32 meysammeysam 211 silver badge3 bronze badges 11
  • why do you need to redirect https to http? – Vishwa Commented Apr 30, 2019 at 7:04
  • @Vishwa because google is indexing both https and http – meysam Commented Apr 30, 2019 at 7:06
  • 1 you dont need to add both to search console. google always prefer https over http. you dont need to add redirect to make google crawl your http version anyways – Vishwa Commented Apr 30, 2019 at 7:08
  • 1 A verry good answer can be found here: webmasters.stackexchange/questions/68435/… – Roy van Wensen Commented Apr 30, 2019 at 11:58
  • 3 I'm curious... if your site is accessible by both HTTP and HTTPS why were you choosing to favor HTTP over HTTPS? Does your site not work properly over HTTPS? I didn't downvote either, but I imagine this is because... .htaccess specific questions are generally off-topic on WordPress SE (these are better suited to the Webmasters Stack). You don't give any specifics as to what "doesn't work"? Errors? Incorrect redirect? Nothing? And... in 2019 there should be no need to redirect HTTPS to HTTP - so what you are suggesting is against all recommendations. – MrWhite Commented Apr 30, 2019 at 17:50
 |  Show 6 more comments

2 Answers 2

Reset to default 2

If available always use https, it is securer for obvious reasons, it is better received by search engines and browsers nowadays, it is just overall preferable.

1 Backup

Should go without saying, but backup your database. There is always a possibility that something goes wrong. Additionally, make sure you have access – ssh, ftp, etc – to your files, and you have a possibility to access – ssh (mysql, wp-cli), phpmyadmin, etc – the database.

2 Set URL

Either under Dashboard > Settings > General:

Or use constants in wp-config.php:

define( 'WP_HOME','https://example' ); 
define( 'WP_SITEURL','https://example' ); 

3 Update database

Either use the Search Replace DB tool:

  • https://interconnectit/products/search-and-replace-for-wordpress-databases/
  • https://github/interconnectit/Search-Replace-DB

Or make use the WP-CLI command search-replace:

  • https://developer.wordpress/cli/commands/search-replace/

Example: wp search-replace 'http://example.test' 'http://example'

Both above options have an option to dry run, test, before making changes.

Bonus, this plugin gets recommended a lot by people I generally trust:

  • https://wordpress/plugins/better-search-replace/

Note: I personally have no experience with the plugin; I'm adding it for completeness’ sake.

4 Enforce redirecting to https

Either via adding the following lines to the .htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Or you can generally set this via your server administration gui, so plesk, cpanel, webmin or whatever your hosting provider is offering.

You can paste this code in the wp-config.php file to define your new URL.

define('WP_HOME','http://yoursite'); //Enter your new URL
define('WP_SITEURL','http://yoursite'); //Enter your new URL
发布评论

评论列表(0)

  1. 暂无评论