Move WordPress to new domain with full URL redirects

Disclaimer: If you break something, too bad. You’re responsible for your actions. This worked for me.
Take backups of your database and files for both domains!

It’s usually not recommended to switch domains since search engines might take some time or not index your moved stuff at all for some reason. Also, frequent visitors might stop visiting your site and old links might stop working after a while if you let the old domain expire…

But lets say you really want to move the domain.
First, it’s important that you use the same permalink settings on both sites otherwise this will not work.

Ok, lets begin, login to WP Admin.
Go to “Tools” and choose “export”.

Export everything and save it as a XML-file.
Don’t worry about the pictures and stuff, WordPress will download that later automatically.

Now, go to your new site and under “Tools” you’ll see “Import”.

Just import it, it might take a while if your site is huge. Don’t click the button twice.

Is the Import OK?
Good. If not… Well, Google and find out what’s wrong.

If it’s good, then login to SFTP/FTP or whatever and open your “.htaccess”-file on the old server and place this bit of code there:

# BEGIN WordPress

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

# END WordPress

Replace my domain name with yours by the way. 😉
Hopefully you got it working with the permanent redirects now!

Make WordPress use HTTPS & WWW & block XMLRPC (.htaccess)

A while back I posted some “.htaccess” code to add HTTPS (SSL) and also “www”, in front of the domain name.

I think it’s a mess to work this stuff and too many people on forums and such tend to disagree about the best way to do things, so I can only assume it’s a common problem. Not to mention the different kind of servers and server configs that can screw things up further.

This is the “.htaccess” code that I currently use on WordPress sites

# Force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# Disallow all WordPress xmlrpc.php requests to this domain
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>

As you can see, it’s checking if the URL contains “www”, if not it will add it. Same thing with HTTPS.

Add HTTPS and WWW to WordPress

Last time I posted, I had a “302” redirect on the SSL stuff which was a mistake because “302” is the code for a temporary redirect.

Since Google decided a few years back to pretty much force people over to HTTPS (Ranking factors..) which really is a good idea, but was a pain in the *ss at the time to make the switch if you got plenty of sites.

Anyway, hopefully you’ve got SSL certificates for your domains by now and therefor we’re telling mighty Google that we’ve permanently moved over to HTTPS. So we should change that temporary “302” redirect to a permanent one “301”.

After that comes the regular WordPress “.htaccess” content.

And last but not least. I decided to block all traffic to xmlrpc.php.
Because it seems to be used by spammers and hackers to bruteforce your passwords.

However, if you use a standalone application to post to your WordPress blogs, like Windows Live Writer for example. You might need to remove that last part of the “.htaccess” code, or why not let your IP in only.

There’s also some plugins that can help you keep the bad guys out if you prefer that approach.

That’s it for now. I’m not 100% this is the best way to do it. Please, leave a comment if you can improve anything in the “.htaccess” code.

UserScript: Back To Old Reddit (Simple Redirect)

Here’s a extremely small but working UserScript to redirect you to “old.reddit.com” if the URL you’re currently are visiting includes “www.reddit.com”.
It doesn’t matter if the URL is to a Sub-Reddit, a post on Reddit or a comment.

I’ve only tested it with “ViolentMonkey” but I think it should work with other UserScript plugins too.

// ==UserScript==
// @name Back To Old Reddit
// @description Redirect you from new Reddit to old.Reddit.com
// @namespace https://www.nordicnode.com/
// @version 0.1
// @match *://www.reddit.com/*
// @author https://www.nordicnode.com/
// @grant none
// @copyright 2019, NordicNode - https://www.nordicnode.com/
// @run-at document-start
// ==/UserScript==

var currentURL = window.document.location.toString();
if(currentURL.includes("://www.reddit.com")) {
var newURL = currentURL.replace("://www","://old");
window.document.location.replace(newURL);
}

Add a “Delete Post” Link to your WordPress Posts!

Add a simple delete link right on your website that is running WordPress. Tested with WordPress version 5.1.

Since the PHP code is written by me it looks like crap, but it doesn’t really matter since the admin is the only one who will see it.

Add this code inside the WordPress loop and reload your website.
If you have logged in as Admin you should see a “[Delete Post]” link somewhere.

When you click it a dialog will pop up, asking you to confirm to delete the post.
I didn’t want the page to reload every time I did delete stuff, that’s why the small iframe is added. It will simply load the delete link inside it. (Told you it was crap code, but it works.)

WordPress Code:
<?php if ( is_super_admin() ) { ?>
<p><a onclick="return confirm('Do you want to delete this post?')" href="<?php echo get_delete_post_link( $post->ID ) ?>" target="deleteframe">[Delete Post]</a></p><iframe name="deleteframe" width="200px" height="35px"><a href="https://www.nordicnode.com/">NordicNode</a></iframe>
<?php } ?>

That’s it!