Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This question came up because if one removes the trailing slash in Google Analytics content drilldown it is listed separate from sub paths. It seems like the more natural behavior from a GA perspective is to enforce having a trailing slash.
Thoughts?
Comments
Comment #1
entrigan CreditAttribution: entrigan commentedI notice that a lot of sites enforce trailing slashes. I think this also plays better with google analytics. Is there a reason not to do this?
Comment #2
donquixote CreditAttribution: donquixote commentedAll link generation in drupal will produce links without the trailing slash. It's not trivial to change that.
Better have no trailing slash than having a redirect on every request.
Comment #3
entrigan CreditAttribution: entrigan commentedhmm, good point. Could not that be solved with a custom_url_rewrite_outbound() function? Either way I am not sure the benefit is outweighed by the cost.
Comment #4
donquixote CreditAttribution: donquixote commentedI am sure you would see a lot of places where this would have no effect, because the module author did not care to use url().
Comment #5
donquixote CreditAttribution: donquixote commentedBtw, you can find a similar discussion for the django framework somewhere, where someone (myself) asked to have an option to have trailing slashes removed. feature was rejected, last time i looked.
i think it depends very much on the framework/platform/cms you use. the authors/maintainers sometimes have a very strong opinion on stuff like that, and think their way is the best. and then there is no option to change it. which makes life a bit easier, if you simply accept it.
Comment #6
Akaoni CreditAttribution: Akaoni commentedI've written code that alters outbound URLs with a trailing slash in D7:
http://drupal.org/sandbox/Akaoni/1145254
Oddly enough, when outbound URLs have trailing slashes, the Global Redirect deslash feature actually enforces them.
Is this code something that could be included in Global Redirect or is URL altering outside it's scope?
It'd need to be back ported to and tested in D6, but with the custom_url_rewrite_outbound() function this'd be easy enough.
Comment #7
Bilalx CreditAttribution: Bilalx commentedI would be interested in drupal 6 version. Right now, i am hacking core and path auto to enforce the use of a trailing slash. And i just realized that i need to hack views too.
Comment #8
Akaoni CreditAttribution: Akaoni commented@Bilalx: Core and module hacks? Yikes!!
You can't just use custom_url_rewrite_outbound()?
Something like:
Comment #9
Bilalx CreditAttribution: Bilalx commentedThanks, it works for arguments in views but not for the base views path.
I still had to hack path.inc to remove the trim from:
$_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
Edit:
Adding:
seems to have taken care of the trailing slash when a view has no arguments.
Comment #10
Akaoni CreditAttribution: Akaoni commentedGlad to help.
Something like this may help for views with and without arguments:
Comment #11
Bilalx CreditAttribution: Bilalx commentedThanks, your code seems to be more comprehensive than mine :)
Comment #12
Akaoni CreditAttribution: Akaoni commentedWelcome. ;)
Since no one related to Global Redirect seems interested, I'll probably release Trailing Slash as it's own project and Global Redirect can then be used to enforce slashes.
This code should come in handy to roll into a D6 version.