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.
By Keith Hurst on
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
Use $_GET
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.
The arg() function uses
The arg() function uses $_GET[], so that won’t make any difference.
___________________
It’s in the detaιls…
demonstration portfolio
It does make a difference.
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.
Not even sure what your solution is.
When you say passing it in www.example.com/alias?x=argument1
, do you meanAnd by , 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
I meant the first
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:
"argument1" prints right out.
Thanks for all your input
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
I was having this issue too
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.
This thread and that little change got it working for me.
Nice one, thanks I'll have a
Nice one, thanks I'll have a look into that.
Keith