My problem is very strange and I haven't found anyone else on here or in any searches on the subject to share this.
In "From" I enter http://website.org/[testpath] (the []'s simply indicate the form text box)
In "To" I enter [http://old.website.org/p/dia/action/public/?action_KEY=3776]
When I click "Save", the redirect url appears with the final slash stripped http://old.website.org/p/dia/action/public?action_KEY=3776
When I try to edit and add the slash back in, same result. Any one know why this might be happening? If I set the url as http://old.website.org/p/dia/action/public/%3Faction_KEY=3776, using the encoding %3F in place of the ?, everything works fine. While this is a "fix", I would prefer the slash would not be stripped out when using a ? immediately after it.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | redirect-allow_trailing_slash-1551224-23.patch | 1008 bytes | acy76 |
Comments
Comment #1
jaydub commentedLooks like this happens during the form validation in redirect_element_validate_redirect() in redirect.admin.inc which in turn calls _redirect_extract_url_options() which calls redirect_parse_url(). The net result being that the URL apart from the query string is set w/o the trailing slash. Any reason why you actually have to have a trailing slash there as that's not the normal form of a URL in this case.
Comment #2
ANDiTKO commentedHave you tried to import your redirects using the CSV import module?
Comment #3
universalhandle commentedI'm experiencing the same behavior. Commenting out line 1285 of redirect.module, i.e.,
resolves the problem. However, having not worked with the Redirect module much in the past, I'm not sure what other repercussions this change would have. Does anyone have any thoughts on that?
In answer to Jaydub's question:
... the answer is that /p/dia/action/public/?action_KEY=3776 is different from /p/dia/action/public?action_KEY=3776. In some PHP applications, the first URL would pass the parameters in the query string to a file located at /p/dia/action/public/index.php, while the second URL would pass the parameters to a file located at /p/dia/action/public (i.e., a file named "public" with no file extension).
It seems to me that:
What would break if we stopped trimming the trailing slash?
Comment #4
capellicI am having the exact same problem as @GinkgoFJG -- it's a DemocracyInAction.org URL that's having it's trailing slash stripped out. Considering that we like to have a short URL on our site to then redirect to the donation for marketing reasons, this has a significant impact on the value of our site.
I have made the change recommended in #3 and tested all my existing redirects. All look good, no bad side effects from what I can tell.
Comment #5
mfbHere's the patch.
The line of code in question has no comments so it's unclear what side effects there might be. However it appears to only be relevant for external URLs - slashes on internal drupal paths are still trimmed with the patch.
Comment #6
rgchi commentedThank you for the patch. This worked!
Comment #7
Maury Markowitz commentedI am also stymied by this problem... I'm redirecting Drupal pages into a Presta ecommerce shop, which uses trailing /s extensively.
How do I apply this patch?
Comment #8
leewillis77 commentedI hit this problem as well, but the patch supplied wasn't sufficient for us. The patch attached works for us.
Comment #9
leewillis77 commentedhttps://drupal.org/node/1812696 closed as a duplicate of this issue.
Comment #11
leewillis77 commentedLast patch was based off the wrong branch - oops. Revised patch attached.
Comment #12
torotil commentedPatch looks good and it passes the tests. Also it doesn't touch the handling of relative vs. absolute paths. Marking this as RTBC.
Comment #13
pere orgaComment #14
dave reidI would think we will actually want to leave this behavior for "internal" Drupal paths, and only leave trailing slashes for external URLs.
Comment #16
mfbPatch at #5 still applies and works as you describe
Comment #17
dave reidNo it does not. It should still trim the trailing slash for local paths. The patch in #5 trims trailing slashes for all paths.
Comment #18
mfbThe patch in #5 trims the trailing slash for all paths unless the URL has a query or a fragment. In this case, the trailing slash is preserved.
I think that's ok because 1) It seems unlikely that a user would accidentally type in a trailing slash to a Drupal path with a query or a fragment; and if they did it would only need to be removed for cosmetic reasons. And 2) It seems good to have similar behavior for all URLs, because redirect module (as far as I can tell) doesn't differentiate between "internal" Drupal paths and other local paths. For example, if you have static content or another web app sharing a base URL with a Drupal site, you may need both external and local URLs to contain
/?So I think #5 is good to commit, but I attached a patch that works as you describe.
Note, some URLs without a query or fragment may also need to preserve a trailing slash. I think this may be what #8 alludes to. That's not what this issue is about, although we could change the title.
Comment #19
mfbComment #20
sonicthoughts commentedcan the trailing slash be a configuration option - would be ideal to let this be explicit since these are nasty things to track down :)
Comment #23
acy76 commentedThe patch in #18 failed to work for me due to a prior call to trim() in the redirect_parse_url() function stripping out trailing slashes. Attached is a refactoring of the previous patch that fixes the issue. Please review.
Comment #24
mfbfor the patch in #23 I'd suggest changing the title of this issue to "External redirect URL that ends with / or includes /? strips / upon save"
Comment #25
acy76 commented@mfb I would agree that a new title might make sense here, since the basic issue is the same whether we're dealing with query parameters or not (i.e., the trailing slash is being stripped in all cases from the path component). How about "Trailing slashes unconditionally stripped from redirect URLs" or something along those lines? Seems to cover both cases.
Comment #26
kvnm commented#18 worked great for me
Comment #27
kvnm commentedComment #28
pifagor commentedRTBC
Comment #29
alex_optim#18 Good for me too.
Comment #30
pifagor commentedComment #33
pifagor commentedComment #34
pifagor commented