Hi,

How can I modify this module for having an end slash on catégories ?

The idea is this:
- I've 2 arcticles: arct1 and arct2
- Both of them ar in the category cat1

I've configured pathauto for having this url:
arct1 => mydomain.com/cat1/arct1
arct2 => mydomain.com/cat1/arct2

And also, I want the url of cat1 listing will be: mydomain.com/cat1/ like a directory and not mydomain.com/cat1

If I've tested to configure like : [cat]/ [cat]\/ [cat]// but nothing works :( .

Can I do this ?

CommentFileSizeAuthor
#7 pathauto-203632.patch617 bytesKingMoore

Comments

billyboylindien’s picture

greggles’s picture

Status: Active » Postponed (maintainer needs more info)

I'm having a hard time understanding how this would help - can you explain what benefit this would provide?

I agree that adding a / to the end of the pattern doesn't work, but I'm not sure why... I think maybe the Drupal path aliasing system doesn't support it.

There is currently code which specifically removes leading and trailing slashes around line 265 of pathauto.inc, so this is being done on purpose.

greggles’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

I guess we don't need this.

KingMoore’s picture

Status: Closed (fixed) » Active

I would like to see this also. I simply want the ability/freedom to specify aliases in pathauto with a trailing slash. Currently if I add a page, and specific 'mycat/' for the page reference, drupal gets confused (5.7) and I get a page not found for both 'mycat' and 'maycat/'.

It isn't nec. about a specific benefit, more than I want this added flexability when choosing an alias. I don't see a negative?

EDIT: it seems that the alias value is getting saved to the db ('mycat/'), so it must be when pathauto does the searching for the alias it strips out the slash, and then searches for just 'mycat' and finds no matches.

KingMoore’s picture

Status: Active » Closed (fixed)

After looking at this more thoroughly, pathauto seems to be doing it's part - the URLs are saved to the url_alias table correctly as 'mycat/'. The problem must be in drupal core somewhere, when it looks at aliases for replacing, it will never find an alias like 'mycat/' because it trims off the slash before doing a search. This issue has nothign to do with pathauto :).

KingMoore’s picture

Status: Closed (fixed) » Active

Nevermind. I am getting confused about what the path module is doing and what pathauto is doing. The PATH module will let me specify and save a url to the url_alias table like this 'mycat/'. Pathauto will let me define a pattern like 'content/[title-raw]/' but the trailing slash does not get saved to the url_alias table.

Sorry for all the back and forth. Like I said, I was a bit confused about what role pathauto was playing in all of this.

KingMoore’s picture

Status: Active » Needs review
StatusFileSize
new617 bytes

Here's a patch that simply leaves the trailing slashes in Pathauto patterns rather than deleting them. Is this patch in an acceptable format? I created it with Zend/Eclipse.

In order for the pages to then be accessed with the /, a small patch would need to be applied to path.module (http://drupal.org/node/250525). However, applying this patch on it's own should not cause any problems.

greggles’s picture

Status: Needs review » Postponed

@KingMoore - thanks for providing the patch.

However, let's wait for #250525: Disallow trailing slashes in path aliases to get committed before doing anything to Pathauto.

aaronnewton’s picture

I am having some difficulty with trailing slashes for pages. Here is what I'm trying to create:

http://foo.com/research/

http://foo.com/research/projects/

However, up until now I have only been able to create http://foo.com/research & http://foo.com/research/projects - the trailing slash seems to break the URL alias. This syntax is more like a reference to a file path on a unix system than an actual directory reference (there are various SEO forums which discuss this problem).

To demonstrate this issue consider this example. If I want to link to http://foo.com/research from http://foo.com/research/projects with relative paths it looks like this -

../../research

Whereas if it were a directory we would just go up a level with

../

Hopefully this will illustrate that the trailing slash is in fact necessary for referencing a tree of resources. Is this an issue with my install or have other people had this problem? To emphasize this point further, please see the Apache docs on the HTML spec -
http://httpd.apache.org/docs/2.0/mod/mod_dir.html (see DirectorySlash Directive). Quote:

Typically if a user requests a resource without a trailing slash, which points to a directory, mod_dir redirects him to the same resource, but with trailing slash for some good reasons:

* The user is finally requesting the canonical URL of the resource
* mod_autoindex works correctly. Since it doesn't emit the path in the link, it would point to the wrong path.
* DirectoryIndex will be evaluated only for directories requested with trailing slash.
* Relative URL references inside html pages will work correctly.

To be fair Matt Cutts does point out that Google can sort of handle missing trailing slashes in this post -
http://www.mattcutts.com/blog/seo-advice-url-canonicalization/

BUT in this post he demonstrates how it can go wrong -
http://www.mattcutts.com/blog/dont-end-your-urls-with-exe/

Since search engines are using a regular expression to decide that a non trailing slash extension is a directory reference, the results can be unpredictable and you are therefore better off using the proper directory path with a trailing slash. Furthermore, if both the slash and non-slash URLs are reachable, this breaks down.

Also, @

The problem must be in drupal core somewhere, when it looks at aliases for replacing, it will never find an alias like 'mycat/' because it trims off the slash before doing a search. This issue has nothign to do with pathauto :).

Does anyone know if it is possible to override this *without hacking?

@ http://drupal.org/node/250525

This is not a great solution since you can still access both the 'file' path and the 'directory' path - it should at least 301 for the incorrect path.

j0hn-smith’s picture

great post aaronnewton

So does anyone know how to do a 301 redirect from domain.com/about-us to domain.com/about-us/? Hacks or no hacks, I don't care (sometimes a solution that uses hacks leads to one that doesn't).

j0hn-smith’s picture

I've written a simple module to provide a 301 domain.com/folder to domain.com/folder/, it won't be suitable for all situations but it's a good start. See http://drupal.org/node/540348

dave reid’s picture

Status: Postponed » Closed (won't fix)

Drupal doesn't care about trailing slashes or not, so I don't think we should be adding this feature or not. I think the Global redirect module can redirect any non backlash-ending paths to ones with blackslashes.

DrupalKing’s picture

There doesnt seem to be a solution here for someone who wants trailing slashes on their URLs. Global Redirect allows for a slash, but that in essence creates duplicate content.

I want pathauto to allow to add a trailing slash to URLs and make that the default behavior.

espirates’s picture

Many want this wordpress like function /page/ Drupal appears to not want it so that's why it's not built in. I personally think the / looks nicer then without and since Wordpress is the leading cms standard, it would be cool to at least provide Drupal users with some base functionality of Wordpress. How cool would that be Drupal with Wordpress functionality, people would not need to use Wordpress anymore.

tobykilroy’s picture

Has anyone had any luck with this yet?
I'm trying to add the trailing slash to taxonomy terms in URL aliases but no luck so far

novakov’s picture

step 1:
file includes/path.inc near 10-15 line find next code

/**
* Initialize the $_GET['q'] variable to the proper normal path.
*/
function drupal_init_path() {
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
}
else {
$_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
}
} 

and change it to

/**
* Initialize the $_GET['q'] variable to the proper normal path.
*/
function drupal_init_path() {
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path($_GET['q']);
}
else {
$_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
}
} 

step 2:
file sites/all/modules/pathauto/pathauto.inc near 300 line find code:

/**
 * Clean up an URL alias.
 *
 * Performs the following alterations:
 * - Trim duplicate, leading, and trailing back-slashes.
 * - Trim duplicate, leading, and trailing separators.
 * - Shorten to a desired length and logical position based on word boundaries.
 *
 * @param $alias
 *   A string with the URL alias to clean up.
 * @return
 *   The cleaned URL alias.
 */
function pathauto_clean_alias($alias) {
  $output = $alias;

  // Trim duplicate, leading, and trailing back-slashes.
  $output = _pathauto_clean_separators($output, '/');

  // Trim duplicate, leading, and trailing separators.
  $output = _pathauto_clean_separators($output);

  // Shorten to a logical place based on word boundaries.
  $maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
  $output = pathauto_truncate_utf8($output, $maxlength, TRUE);

  return $output;
}

and replace it with

/**
 * Clean up an URL alias.
 *
 * Performs the following alterations:
 * - Trim duplicate, leading, and trailing back-slashes.
 * - Trim duplicate, leading, and trailing separators.
 * - Shorten to a desired length and logical position based on word boundaries.
 *
 * @param $alias
 *   A string with the URL alias to clean up.
 * @return
 *   The cleaned URL alias.
 */
function pathauto_clean_alias($alias) {
  $output = $alias;

  // Trim duplicate, leading, and trailing back-slashes.
  // $output = _pathauto_clean_separators($output, '/');

  // Trim duplicate, leading, and trailing separators.
  $output = _pathauto_clean_separators($output);

  // Shorten to a logical place based on word boundaries.
  $maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
  $output = pathauto_truncate_utf8($output, $maxlength, TRUE);

  return $output;
}

(we just commented one line)
now i have ability to set up patterns in pathauto settings with ending slash, like content/[title-raw]/ and it works great
i`m using Drupal 6.20 and Pathauto 6.x-2.x-dev, be carefull with updating Pathauto and Drupal core - dont forget to make changes again

langelhc’s picture

Issue summary: View changes

If someone is going to need this funtionality you can see: https://www.drupal.org/project/trailing_slash