Redirect URLs with Jekyll

153 Views Asked by At

I migrated to a Jekyll website from WordPress. Now I already manage redirect with jekyll-redirect-from plugin. My website is hosted on Github Pages which doesn't give me access to .htaccess file.

I know how the Jekyll Redirect From plugin works.

I need to redirect images to different URLs without losing images I have already indexed in Google. Is there a way to do it?

In Google Search Console I see a lot of pages detected but not indexed that have URLs like this:

<my website>/post/?doing-wp-cron=xxxxxx

I think these URLs come from the old website on WordPress where the cron task was active.

I want to redirect all the URLs:

<my website>/post/?query-id=value

in:

<my website>/post/

Basically, I want to redirect URLs with query string to same URLs but without query strings. Is there a way to do this in Jekyll on Github Pages?

1

There are 1 best solutions below

0
Christian On BEST ANSWER

A solution to this problem would be to use JavaScript to parse the URL and perform the redirect:

if (window.location.href.indexOf("?query-id=") > 0) {
    window.location = window.location.href.split("?")[0];
}

This solution redirectd any URL with a query string to the same URL without the query string.