Redirecting old blog posts

Hi,

I’m rebuilding my the Blog for my teachers resources website.

I need then to redirect older posts to the new blog as some of the pages still get great traffic, for example

https://www.themagiccrayons.com/blog/?post_id=21

Thing is, I need to create page called “?post_id=21” onto which I will place a redirect stack.

RW won’t of course let me create a folder that begins with a question mark, a non alphanumeric character

Any suggestions?

Thank you

TIm

Just redirect them in the .htaccess file no need to build a page to do it

1 Like

Hi Scott,

Sounds a plan. Would you have a link please where I can learn how to do that ?

Thank you

Tim

There’s many tools out there that will help you format the htaccess file redirects.

The basic format would be something like this

Redirect 301  /oldblog/?post_id=21 /newblog/?post_id=21

I would probably get one of many tested and working first then replicate the line.

This post has a link to the video using the RW8 htaccess tool:

1 Like

Hi Doug et al,

Thank you for your help.

I’m new to editing the .htaccess file and I’m not complete being successful .

As a test, these work fine
(non existent page redirect to blog error page)

Redirect 301 /animals/fish.html /303-oops-blog
Redirect 301 /animals/fish /303-oops-blog

But these do not
(non existent blog page redirected to error page)

Redirect 301 /blog/?post_id=199&title=cats.html  /303-oops-blog
Redirect 301 /blog/?post_id=199&title=cats  /303-oops-blog

I can’t see why one works and the other does not.

I have a separate blog error landing page and 404 error landing page.

The blog address is

https://www.themagiccrayons.com/blog/

http is redirected to https by Cloudflare. The blog is Armadillo.

Any suggestions on how to proceed would be much appreciated.

Thank you

Tim

Some extra info…

If I go to a made up blog post URL

https://www.themagiccrayons.com/blog/?post_id=1234567

It will load Armadillo (sidebar, categories etc), but just display an empty post. I’d expect it to give me an error for a non existent page.

ty

Yeah,
looking at it closer I see the issue. You are redirecting a page with an HTML query string attached( the Stuff following the ?). That dynamically generated address probably can’t be handled by a “single line” redirect rule but would need a more complete RewriteRule to handle the query string. So there are a number of ways to handle that.

Some questions are you keeping the “query string” (stuff after the ?) the same on the new page?

if so a single rule set should work:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^\/blog
RewriteCond %{QUERY_STRING} ^post_id=([0-9]*)
RewriteRule ^(.*)$ https://www.themagiccrayons.com/newblog/%1 [R=301,L]

The above would redirect as the following:
Entered URL:
https://www.themagiccrayons.com/blog/?post_id=199&title=cats.html
Should get redirected to:
https://www.themagiccrayons.com/newblog/199?post_id=199&title=cats.html
Entered URL:
https://www.themagiccrayons.com/blog/?post_id=133&title=how-a-car-engine-works
Should get redirected to:
https://www.themagiccrayons.com/newblog/133?post_id=133&title=how-a-car-engine-works


Are you wanting to change to A URL without a query string(no ?)?

If so the rules become more complicated. You will need to specify a rule group for each page(post). this example shows 2 posts (199 & 133)

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^\/blog
RewriteCond %{QUERY_STRING} ^post_id=199
RewriteRule ^(.*)$ https://www.themagiccrayons.com/newblog/new-post199/? [R=301,L]
RewriteCond %{REQUEST_URI}  ^\/blog
RewriteCond %{QUERY_STRING} ^post_id=133
RewriteRule ^(.*)$ https://www.themagiccrayons.com/newblog/new-post133/? [R=301,L]

Entered URL:
https://www.themagiccrayons.com/blog/?post_id=199&title=cats.html
Should get redirected to:
https://www.themagiccrayons.com/newblog/new-post199/

Entered URL:
https://www.themagiccrayons.com/blog/?post_id=133&title=how-a-car-engine-works
Should get redirected to:
https://www.themagiccrayons.com/newblog/new-post133/


Are you wanting to change to A URL with a NEW query string)?

Again very similar to above need a sele set(3 lines) for each post. Just put the query string after the ?.

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^\/blog
RewriteCond %{QUERY_STRING} ^post_id=199
RewriteRule ^(.*)$ https://www.themagiccrayons.com/newblog/?this-is-the-new-query-199 [R=301,L]
RewriteCond %{REQUEST_URI}  ^\/blog
RewriteCond %{QUERY_STRING} ^post_id=133
RewriteRule ^(.*)$ https://www.themagiccrayons.com/newblog/?this-is-the-new-query-133 [R=301,L]

Entered URL:
https://www.themagiccrayons.com/blog/?post_id=199&title=cats.html
Should get redirected to:
https://www.themagiccrayons.com/newblog/?this-is-the-new-query-199

Entered URL:
https://www.themagiccrayons.com/blog/?post_id=133&title=how-a-car-engine-works
Should get redirected to:
https://www.themagiccrayons.com/newblog/?this-is-the-new-query-133

The page exists just not the post.

1 Like

Hi Doug,

Wow and thank you for your time and shared expertise.

It’s the later of the three that I will need for posts that I am going to still keep available. I’m replacing one blog plug in with another. The new one uses query strings too. I’ll use the middle one to point to an error page for posts I am not keeping.
I’m going to back up everything, make a large coffee, and free up some time at the weekend to give it a go. Once
I can get one working it will just be a large cut n paste session. It’s imperative I keep some older posts. There are plenty from ten years ago that need to go, but there are websites and blogs that still point to them

Thank you again - Tim

By the way,
If you want to “test” the htaccess file first there’s a great website for that.
https://htaccess.madewithlove.be/

Just paste the htaccess file into the large area enter the URL from the old posts (one at a time) and hit the test button. The bottom area will show the results as well as the URL it will be redirected to.

With as many as you are doing I would probably make up a plan text document with a full URL for each post. Then copy one at a time and test making sure it works and goes to the correct new page.

Hi Doug,
That looks useful.
I ended up with a 550 line htaccess file of redirects! The blog is some ten years old mostly of educational software resources the majority of which no longer exist or the blog I linked is no longer online. Took a while to do but at least all the content is now relevant. Need to remake all the thumbnails and update a few posts but it’s good enough for now. I’ve a couple of rouge redirects but the link you just given should find those.

The main thing is that the popular posts are redirecting fine and weren’t off line for a significant period of time.

https://www.themagiccrayons.com/blog/?post_id=21

Thank you again

Tim

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.