Thursday, 7 May 2020

How To Change Default Permalink Structure in Blogger

Hello everyone today I am going to show you a way to remove the default permalink in the Blogger. WordPress already has this feature that Blogger lacks. Seems like Google Blogger is little serious about its security or want to prevent spam or misleading URL structures. What you think about it? Let me know in the comments below!

Well, Blogger chooses its default permalink scheme as follows -
For Posts : https://my-blog.blogspot.com/YYYY/MM/your-post-name.html
For Pages : https://my-blog.blogspot.com/p/your-page-name.html

The permalink structure for posts looks very long and annoying and also hard to read. Better than that, we can use something like https://my-blog.blogspot.com/your-post-name.html would be great.

Now its time to dive into the code, the below given JavaScript code is minified. But you can get the original version on the GitHub.
<script type='text/javascript'>
//<![CDATA[
//==Css-magz.blogspot.com/==V1.0==PermalinkChanger==
function GetFilename(url){if(url){if(url.lastIndexOf(".html")>-1){var a="/"+url.substring(url.lastIndexOf("/")+1,url.lastIndexOf(".html"));
return a}}return ""}function rpl(str){if(history.replaceState){history.replaceState("obs","",str)}else{console.warn('Use Latest HTML5 browser!')}}var path=window.location.pathname;
var count=(path.match(/[/]+/g)||[]).length;if(count==3){var ch=GetFilename(path);rpl(ch)}else if(count==2){var ch=GetFilename(path);rpl(ch)}else{console.log('If page not found, add an redirect URL or move to HOME')}
//]]>
</script>
Whatever the code below does is uses the history.replaceState function to change the URL of the blog. That is - it takes the /YYYY/MM/your-post-name.html and change it to /your-post-name.
It does similar thing to pages.It doesn't refresh the page while doing so(good for us).

Now the problem occurs! if someone shares your post with the URL having /your-post-name.html then blogger returns with 404 error. Pretty bad isn't is?

But we can use Blogger's Custom Redirects to redirect the page to its original designation so that user can able to view your post.

I've discussed the Implementation of the code below.


Implementing the code


Copy the given below and add it before the <head> tag. For doing that -

  1. Log into your Blogger account and go to Theme.
  2. In the Theme section, click on the Edit HTML
  3. Just below <head>, put the above code and click on Save.
    Permalink changer blogger
Now lets check our blog. Go to any post on your blog and BOOM! You can see there is no year and month in the URL.

That's perfectly fine. But now suppose if anyone want to share your blog post, he'll surely copy /your-post-name and not /YYYY/MM/your-post-name.html. That means when anyone will open that link, Blogger will return a 404 not found error.

Now how to solve this problem? We can use Blogger's Custom Redirects .

If you set custom redirects, then Blogger will automatically redirect /your-post-name to >>> /YYYY/MM/your-post-name.html and then JavaScript will do its work to show our custom URL.

For that,
  1. Go to Blogger and click on Settings.
  2. Go to search preferences and in Errors and redirection , Click on Edit in-front of Custom redirects.
    Custom redirects blogger
  3. Add the from URL. Eg. /your-post-name to YYYY/MM/your-post-name.html
Now even if anyone lands on our custom URL, it will automatically redirect it to original and then JavaScript will automatically change to URL in URL bar. This will happen within fraction of seconds - exactly like the normal page load.

You'll need to set every URL in the custom redirects, which I know is not very much practical. If you have a new blog than this might be for you.


Also, there is no Blogger API support for the custom redirect or else would have been an easy task. :(

Impact on SEO


Now the question is - will this have any impact on SEO? No! It would not have any bad as will as good impact on your SEO.

All our custom URLs are just for anyone to understand and remember better. There is not a valid proof anywhere as your URL should not contain any year or month or else Google will ignore that. There's no thing as such. Its always better to have URL that matches with your post title. I've even seen many links in the search results whose URLs are like https://we.bsite.com/post-36742.

Important are only three things - Title , meta description and the main content of the post.

If you came across any problem, just leave a comment below and I'll surely help. Don't forgot to subscribe this blog if you haven't already.

2 comments:

  1. this is all i ever wanted and never even knew was possible.
    so glad you are back with awesome tips and tricks! <3

    ReplyDelete

Comment something useful and creative :)