Hello,
When I create redirect with source path like this: "info2lf/ustavy/ik/" it will return 404 when loading "info2lf/ustavy/ik" or "info2lf/ustavy/ik/". When I remove slash at the end in this redirect source, it will redirect correctly with or without slash at the end.

Comments

pere orga’s picture

Status: Active » Postponed (maintainer needs more info)

Using the dev version, I can't reproduce the problem creating redirects using admin/config/search/redirect/add.

Could you specify the steps to reproduce this issue in a clean Drupal 7 install?

honza pobořil’s picture

Sorry for not mentioned it here, I create redirects by the API function redirect_save().

pere orga’s picture

Status: Postponed (maintainer needs more info) » Active

Ok I'll have a look

pere orga’s picture

I can reproduce the issue. The issue can't be reproduced using the Edit Redirect form because the slash is trimmed after submit, and when a redirect is created without a slash, both paths work.

Apparently the Drupal core's Path module is having the same problem. Aliases created with a trailing slash can't be reached.

I guess we could 'fix' the issue trimming the trailing slash inside redirect_save(), so both paths (with and without slash) work when a redirect with a trailing slash is passed through the function.

dave reid’s picture

If you're using the raw API, it's typically the responsibility of the module calling the API to make sure it is passing valid data.

pere orga’s picture

But why the data is not valid? He is trying to add redirect with a trailing slash.

dave reid’s picture

It has been a long-standing standard that save API functions do as little processing as possible. If path_save() were to also do this or similar, then I would gladly accept this change for redirect_save() as well. A redirect with a trailing slash on it is not a vaild source path, hence invalid data.

pere orga’s picture

I agree that what I proposed is a bad idea, it was more a workaround that could have other implications.

The issue here is that paths ending with a slash can't be inserted independently (without inserting a path without the slash, I mean), which I guess is what the original poster was trying to do. So it's not possible to have a redirect with source path /source-name/, without having one with the /source-name path. But this is not an issue of redirect_save(), it does not work either if I manually insert a path ending with a slash in the source column of the redirect table.

Is that a won't fix ticket?

pere orga’s picture

Apart from that, I still don't see why you consider a path ending with a slash invalid, to me it makes sense to consider it valid.

dave reid’s picture

Status: Active » Closed (won't fix)

One reason I consider it invalid, is because modules should check to see if a redirect already exists before it can be saved, otherwise it will throw errors on save. Typically this is done using the following:

    redirect_object_prepare($redirect);
    // Check if the redirect exists before saving.
    $hash = redirect_hash($redirect);
    if (!redirect_load_by_hash($hash)) {
      redirect_save($redirect);
    }

If an existing redirect is there, but we're trying to save a duplicate redirect with a trailing slash, this will cause errors.

pere orga’s picture

Makes sense

honza pobořil’s picture

Or should not this validation be part of redirect_object_prepare()?

If you think this validation is responsibility of modules using the API, you should document this requirement (to not have slash at start or end of path).

pere orga’s picture

Component: Code » Documentation
Category: Bug report » Task
Status: Closed (won't fix) » Active

Yes, that's a good idea. Let's document it.

sonicthoughts’s picture

I believe this works differently than the global redirect module. I switched and am working with civicrm, which is a seperate application that integrates with drupal on the same server. If I want to redirect domain/test to civicrm/event/info?id=808&reset=1/ it will not work properly. Also, it sometimes expands with a backslash at the end with redirect vs. globalredirect (which I haven't quite figured out yet ...) just another consideration, I'm not sure what the best approach is but wanted to make sure you understood the use case.

wylbur’s picture

Status: Active » Closed (outdated)

Marking this as Outdated as drupal 7 is EOL.