jekyll-redirect-from
                                
                                
                                
                                    jekyll-redirect-from copied to clipboard
                            
                            
                            
                        Pass parameters and anchors in URL to redirected page
Summary
This change allows anchors (#heading) and parameters (?q=a) in a URL to be passed along to the redirected page. The use case for this would be when linking readers to a specific section of a page, and wanting the link to work for either the permalink page or the redirected page. I don't have a use case for query parameters, but it's the same idea so I don't see why not.
Current
If oldPath/index.html
redirects to
http://jekyllrb.com/2014/01/03/redirect-me-plz.html
Then any link containing anchors or parameters is broken, such as the following:
http://jekyllrb.com/oldPath#important-subsection?question=answer
Will redirect to the base page, stripping off the extras:
http://jekyllrb.com/2014/01/03/redirect-me-plz.html
Proposed
I propose that the link:
http://jekyllrb.com/oldPath#important-subsection?question=answer
Should redirect to
http://jekyllrb.com/2014/01/03/redirect-me-plz.html#important-subsection?question=answer
Technical Details
- The first script now appends 
location.hashandlocation.searchto the jump location. - The backup redirect solutions - the refresh meta tag and manual redirect links - are edited in a secondary script to append 
location.hashandlocation.search. - If JavaScript is turned off, it will redirect to the base URL without anchors or parameters
 - I don't think location.hash or location.search can be null or undefined, but just in case, there are null/undefined checks to make them explicitly be "".
 
Bump
Bump2. Anyone checking this repo?
Hello, this addition is rather useful. Can we get someone to merge it in?
maybe @ashmaroli , @DirtyF , @parkr ?
Can we bump this? @DirtyF I'll just tag you since it seems you've contributed recently.
Hello everyone, I've taken a look at this. The patch introduces a significant amount of JS code without test coverage. That is not acceptable. Why not handle the computation in Ruby itself instead of JS?
Thank you for taking a look @ashmaroli.
This was months ago but if I remember right, it's because you want to be able to redirect to specific anchors on the permanent page, which happens dynamically. I don't think you can do it in Ruby (which runs at site build time) unless along with registering the redirect you somehow also registered all anchor and parameter possibilities.
At least, I cannot think of a way. But I am no Ruby expert by far. If you have an idea, please let me know and I will be happy to try my hand at an alternative solution.
If not, how do you propose increasing test coverage? The current test framework can only test Ruby code if I'm not mistaken.
to be able to redirect to specific anchors on the permanent page, which happens dynamically..
Oh right. There's no easy way to this before hand. We sure are in a sticky situation here..
Ref: https://github.com/jekyll/jekyll-redirect-from/issues/219