"?" not supported in a path alias?

geilhufe - February 11, 2007 - 18:41
Project:Drupal
Version:7.x-dev
Component:path.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I am trying to create a path alias for "civicrm/contribute/transact?reset=1&id=4"

I have tried escaping the characters without result. It seems like the alias works all the way up the the "?" then basically doesn't pass any of the arguments past the "?".

I am thinking this might be related to clean URLs and .htaccess doing something to the question mark. I am not a programmer, but more that willing to test and debug if provided a little direction.

#1

revival - February 26, 2007 - 13:38

am having the same problem

#2

leafish_paul - July 17, 2008 - 11:52

Just noticed this myself, and I posted what I'm up to on this issue. Perhaps related?

#3

pvasener - May 6, 2007 - 00:35

I also have the same problem. It seems that the alias in only valid for the part before the exclamation point. BTW, the link you provided above about another maybe-related issue is broken. Can you advise?

#4

leafish_paul - May 13, 2007 - 08:04

Oops: issue.

#5

tobias - November 14, 2007 - 17:56

I'm struggling with this issue myself - esp using civicrm which produces attrocious URLs.. though it also happens when creating menus. Has anyone found a solution to this problem?

#6

mfb - November 14, 2007 - 20:36
Project:Path» Drupal
Version:» 7.x-dev
Component:Code» path.module
Category:bug report» feature request

Moving this over to a feature request on drupal core.

#7

tobias - January 30, 2008 - 05:08

Hi,

Any news with this issue? It is severely hampering my abilities to create clean URLs for civicrm profile pages which I'd very much like to do.

Many thanks in advance for any insights,

Tobias

#8

imrook - March 23, 2008 - 00:28

I have recently run into this problem and have a solution that meets my needs so I'll chime in with my two cents here. The part after the '?' character in the URL is called the query string. boombatower created an issue with a patch for this problem here. Some users complained that it didn't work -- I personally haven't tested it. chx doesn't seem too intent on adding the functionality at this time.

But there is still hope. Here's why the problem occurs in the first place: Apache uses mod rewrite to rewrite a URL like http://mysite.com/drupal/admin/build/menu to become http://mysite.com/drupal/index.php?q=admin/build/menu. During the bootstrap phase, Drupal uses the value of the variable $_GET['q'] to map a URL to a function call. Now look what happens with the following URL: http://mysite.com/drupal/path_alias?myvar=1 Apache's mod_rewrite turns it into http://mysite.com/drupal/index.php?q=path_alias&myvar=1 This is normally a good thing. The problem with Drupal is that the core doesn't look at any other variables besides $_GET['q'] so it will only use path_alias for the lookup. Luckily Drupal provides a place where we can change that: custom_url_rewrite() Add the following code to your settings.php file:

<?php
function custom_url_rewrite($op, $result, $path) {
  global
$user;

  if (
$op == 'source') {
   
// Get extra variables from URL
   
if (isset($_SERVER['QUERY_STRING'])) {
     
//Remove the 'q=' and change the first & into a ?
     
$query = preg_replace('/^q=([^&]*)&(.*)$/', '\1?\2', $_SERVER['QUERY_STRING']);
    }
   
// See if we have a url_alias for our new path
   
$sql = 'SELECT src FROM {url_alias} WHERE dst="%s"';
   
$row = db_result(db_query($sql, $query));
    if (
$row) {
     
// We found a node source path
     
$result = $row;
    }
  }

  return
$result;
?>

}

This will allow you to set a path alias for a node that contains a query string and Drupal will redirect to the correct page. Note that when Drupal generates a link to the node it will be urlencoded, but it will still work properly.

This code is actually written for 5.x In Drupal 6, the function is called custom_url_rewrite_inbound and the parameters have changed a bit. I haven't taken a look at 7 yet so I don't know anything about that.

#9

tobias - March 24, 2008 - 16:29

very nice! I have implemented this and it seems to work very well for my site.

One issue I still run into is with a custom civicrm signup form which breaks upon submission when I use your hack with a "Cannot add or update a child row: a foreign key constraint fails" error. Not a big deal since I have already setup apache redirects for these signup forms.

But your hack will help with accessing other civicrm pages from the menu. Many, many thanks. You've addressed one of my major issues with civicrm. I'll be sure to spread the word in the civicrm forum if you have not done so already.

Cheers,

Tobias

#10

imrook - March 25, 2008 - 20:01

One issue I still run into is with a custom civicrm signup form which breaks upon submission when I use your hack with a "Cannot add or update a child row: a foreign key constraint fails" error.

Since I'm not using CiviCRM, I'm not very surprised that this approach has some flaws with that module. I did think what I had was relevant and may be a good starting point for others, which it appears is correct. I'm glad I could help at least some with this issue. Since I'm not using CiviCRM, you can feel free to mention this method in that forum but beware that people will probably come back with posts citing all the things that still don't work correctly.

#11

Damien Tournoud - March 25, 2008 - 20:24

Subscribing. We need a better solution for that issue.

#12

imrook - March 27, 2008 - 16:15

I kinda thought this was too good to be true. I found a problem with the code in comment #8. If a user has "administer menu" permission and edits a node, the cached menu tree that is created will have all menu links pointing to the current node. If you are bittin by this, clear your menu cache with "DELETE FROM cache_menu;" Unfortunately, I haven't found a way to fix this in custom_url_rewrite and have resorted to hacking path.inc during the drupal_init_path() call. I'm interested to see if anyone can find a solution that works within custom_url_rewrite.

#13

haggan - April 22, 2008 - 20:14

Is this drupal 6-7 specific or does this hack work on drupal 5.7? I cant get it to work, when I paste it into my settings.php my webpage is just blank...

#14

tobias - April 23, 2008 - 03:11

this worked for me on drupal 5.3, except for the civicrm issue I explained above which is why I don't use it.

cheers,

tobias

#15

sonicthoughts - May 6, 2008 - 02:46
Version:7.x-dev» 5.6

Yes - please fix - you can't add any civicrm menus to drupal without a hack. I have found nothing that works with 5.6

#16

spatz4000 - May 6, 2008 - 12:31
Version:5.6» 7.x-dev

features should go into the latest dev version and then backported.

#17

geilhufe - June 4, 2008 - 18:42

Theoretically resolved in Drupal 6:
http://drupal.org/node/90570

#18

geilhufe - July 16, 2008 - 22:19
Status:active» fixed

Fixed in Drupal 6.x / CiviCRM 2.1+

#19

Anonymous (not verified) - July 31, 2008 - 11:54
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#20

himtuna - August 1, 2008 - 06:05

thanks for that fix, I was realy getting annoyed from it.
www.himtuna.com

#21

Damien Tournoud - November 14, 2008 - 18:03
Status:closed» active

How that is fixed?

 
 

Drupal is a registered trademark of Dries Buytaert.