Hi,

I'm currently switching a site over from old hand-rolled PHP code to Drupal, and have run across one problem. We were using rewrite rules in htaccess like this

RewriteRule groups/(.*)$ groups.php?p=$1

so people going to

http://site.org/groups/group-name

would get redirected to

http://site.org/groups.php?p=group-name

and we would use $_GET[p] in the script to extract the $group-name variable to use in the script for pulling out page content.

How can I replicate this with Drupal? A visitor goes to http://site.org/groups/group-name and $group-name is pulled from the URL and passed as a PHP variable to the script on the group-name page.

The old htaccess rules don't work, and I've tried using arg() but that didn't work - it just returned the node ID number.

Any ideas?

Thanks!

Comments

hagrin’s picture

Ok, a few things ... IF, and I stress if, I understand this correctly.

First, by default, Drupal doesn't use the URL structure that you need by default. Therefore, you need to move away from the default URL structure that relies on querystrings. Have you tried implementing the Clean URLs, path, pathauto and global redirect modules? I would look into those since those are the modules that best handle URL rewriting in Drupal. I actually wrote a guide for this a while back - http://www.hagrin.com/306/seo_drupal_5_creating_search_engine_friendly_urls - that might be able to help you figure out how all the modules interact with each other.

That should get you the URL structure you need.

Now, to get the groups and group names, you would need to enable the Taxonomy module and then put your previous, old content and assign categories to it so that when you go to a taxonomy page, that will mimic your old "group names".

Once those things are done, you should be able to use a very similar .htaccess rule that you used to use to grab the category name from the URL and then rewrite the URL with a querystring p=category.

Sorry if I am off base here, but I "think" that's what you are looking to do.

paul-c’s picture

Thanks for that, I had everything set as you suggested except wasn't using autopath, so installed that and I'm getting closer, the URLS are in the form I want: http://site/group-name/term

What I'm having trouble with now is with arg() - it returns the term id but how do I get the term name?

--------------------
http://noise.as/
E-Commerce module in action - music for sale!

paul-c’s picture

Let's try asking again, I hope someone can help out.

With an URL in the form: http://site/cat/term I need to get $term to plug into a script. I know it must be simple, but I can't find any details how to pull it from the URL. Tried using arg(), but that returns the term id rather than the term itself

How do I get the term name?

Thanks in advance!

--------------------
http://noise.as/
E-Commerce module in action - music for sale!

modul’s picture

I think this is what you're after:

$your_tid = 1045;
$x = taxonomy_get_term($your_tid);
echo "When your taxonomy term number is " . $your_tid . " then " . $x->name . " is the corresponding term name.";

The $your_tid variable can be obtained with arg(2), if I'm not mistaken. Obviously, a few checks would have to added to this code, is_numeric etc.

paul-c’s picture

That's exactly what I was after.

Thank you so much!

--------------------
http://noise.as/
E-Commerce module in action - music for sale!