Currently redirecting based on a wildcard is not possible. I made a patch that uses the * as a wildcard in URL redirects.
Also added a speed optimization from the front-page OR condition to a IN condition which is about two times faster.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | add-wildcard-redirecting-2562455-9.patch | 2.17 KB | pdenooijer |
Comments
Comment #2
pdenooijer commentedAdded organization.
Comment #3
legolasboDevelopment happens on dev branches ;)
Your patch seems to be doing what it claims to do, without breaking existing functionality. I did find some issues with the code though.
I guess this is another optimisation.
By not checking if the field exists you save a database query at the expense of generating errors on websites where the update script hasn't been run. Even though this is out of scope, I think it should be committed. Anyone who updates his modules and doesn't run update.php will have other problems besides an error message.
Let's make this:
Could you reformulate this comment to be more clear? I understand what the for loop does, but I'm not really sure what you mean with the comment.
I guess this is what you mean? This seems a little out of scope to me. But I don't see a reason why it shouldn't work. I guess it's up to the maintainer and can be removed at commit.
Comment #4
pdenooijer commented1. Yep, your right! I forgot to document that. I completely agree with you that administrators should run update database, so for now I let is be.
2. I use $length because later on I use it again in the for loop.
3. Could this be a better way of commenting:
// Generate the wildcard search URLs, replacing the remaining elements with the wildcard. The first URL will always contain at least one element before the wildcard.
4. I'll leave it in for now.
Comment #5
legolasbo3. Yes better, but we're not mentioning URLs anywhere in the code, perhaps another term?
Comment #6
pdenooijer commented3. Could this be a better way of commenting:
// Generate a wildcard sources array, replacing the remaining elements with the wildcard. The sources will always contain at least one element before the wildcard to prevent infinite loops.
Comment #7
legolasboSounds good to me. Please upload a new patch so i can RTBC it.
Comment #8
dave reidAs a maintainer, I have taken a firm position that Drupal (and hence the Redirect module) is not the best layer for wildcard redirects. These should be done at the server/.htaccess level. That said, someone has wrote a module that supports wildcards already: https://www.drupal.org/project/match_redirect which is linked from the project homepage.
Comment #9
pdenooijer commentedWith all due respect, but could you elaborate on why you have this firm position against wildcard redirects?
All redirects in the whole redirect module can be done in the htaccess, so from that point of view the module would be obsolete. The match_redirect module uses entities to fix something that redirect module can do with less overhead. As you can see my patch doesn't add that much logic and only one database query like the original. This could be very handy for everyone that has no access to the .htaccess file on the server, lacks the technical know how to do so or wants to have the ability to add a (temporary) redirect, on the fly, without the possibility of making the website unreachable due to a typo in the .htaccess.
Comment #10
dave reidSee previous discussions at #963668: Mention the Match Redirect module on project page / documentation or any of the discussions in path_redirect. Redirect itself uses entities to store the redirect. It provides a pluggable API so that other modules could provide alternative redirect types, like 'wildcard' instead of 'redirect'. But I stand firm that I do not want that to be the responsibility of this module. Yes, all redirects can be done in .htaccess. But when you are using Pathauto, you are working with individual changing aliases at a time. This is why it makes sense to manage these in Drupal. In fact, I usually recommend regularly exporting all the Redirects to .htaccess to avoid a Drupal bootstrap for those.
Comment #11
pdenooijer commentedThanks for the answer Dave, I can understand your point of view. Now people will find this link as well when they search for wildcard redirecting as added bonus.
For now I use my patch for my own problem and maybe I'll make it into a module using the API you provide :).
Comment #12
kenorb commentedDrupal 8.x: #2831605: Support for wildcards
Comment #13
klonosI see that this feature is now being considered and being worked on for 8.x. Would it then make sense to re-open this issue here, and backport whatever solution into 7.x?