I have created a page in Drupal, this page lets say can be reference...

?q=node/21

Using the Path URL setting I aliased this to testnode

So I can reference the page via http://mysite/?q=node/21 or http://mysite/testnode.

However this page constructs and executes a SQL statement based on parameters in the URL.

I can reference http://mysite/?q=node/21/argument1 and right enough in my php code arg(2) is set to the value argument1.

If I reference http://mysite/testnode/argument1 I just get a Page not found page. So how do I pass in arguments into aliased URLs ?

Thanks
Keith

Comments

zbricoleur’s picture

It may be possible to pass Drupal-style arguments behind an alias, but I don't think so, because of the way Drupal parses URLs. But you can still pass in parameters using the ?x=y syntax.

zeta ζ’s picture

The arg() function uses $_GET[], so that won’t make any difference.
___________________
It’s in the detaιls…

demonstration portfolio

zbricoleur’s picture

I tested it both ways. Passing it in as you have done results in a 404; passing it in using ?x=y works like a charm.

zeta ζ’s picture

When you say passing it in using ?x=y, do you mean www.example.com/alias?x=argument1
And by use $_GET, do you mean $_GET['x']

Or do you mean www.example.com/?q=alias/argument1 and $_GET['q'] ?

I assumed you meant the latter, as it is closer to the way Drupal normally works. I’m fairly sure the first will cause problems later on, with clean url’s enabled.
___________________
It’s in the detaιls…

demonstration portfolio

zbricoleur’s picture

www.example.com/alias?x=argument1

I have clean URLs enabled, and this works fine for me--at least, I've seen no problems so far. I made a page, gave it an alias, and used this for the body field, using the PHP Code input format:

print $_GET['x'];

"argument1" prints right out.

Keith Hurst’s picture

Thanks for all your input here...

I tried the www.mysite.com/testnode?x=argument1 and I still get the 404, doesn't even get to my PHP. Like yourself I have clean URLs enabled.

I'll stick with the ?=node/21/argument1 syntax for just now as that's at least functional if a little unsightly and I'll come back to this one later.

Many thanks
Keith

BradleyT’s picture

I was using drupal_goto on a little custom search box I made to send visitors to a page with their term as the querystring parameter. It kept giving me 404's when trying to go to example.com/page?x=arg however if I typed that URL directly into the browser then $_GET['x'] was working. I figured out that drupal_goto needed the URL in a different format than what I was trying.

It needs the querystring parameters into the second parameter of the function call.

$url = "page";
$query = "x=hotdogs";
drupal_goto($url, $query);

This thread and that little change got it working for me.

Keith Hurst’s picture

Nice one, thanks I'll have a look into that.

Keith