Hello all-

I am trying to add an additional RewriteRule in .htaccess for a drupal page that I have created. The page is actually making some calls to the database, which is working fine, but currently the url structure looks like this:

http://drupal/location?state=ca&city=sacremento

That works just fine, however I'd like to turn that into this:

http://drupal/location/ca/sacremento

My .htaccess looks like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteRule ^location/(.*)/(.*) index.php?q=/location&state=$1&city=$2 [L]

I bolded the changes I've made to .htaccess.

Unfortunately, the above method isn't working. I keep getting a 404 when I try to visit the clean method /location/ca/sacremento.... It works just fine when I pass it like a query string.

Any ideas on to how to make this work?

Comments

coreyp_1’s picture

This may be a dumb question, but why are you trying to do this? is it for a view?

- Corey

drshields’s picture

Yeah, I guess you could call it that. It's basically a drupal "Page" that has some embedded php code making some db calls. So, the following url:

http://drupal/location/ca/sacremento

would REALLY be processing /location?state=ca&city=sacremento

In the pages content, I'm embedding some php:


$state = $_GET["state"];
$city = $_GET["city"];

//...logic here...

Does that make sense?

coreyp_1’s picture

The reason I am asking is because Drupal has a built-in function to help with things like that. It's called arg().

Suppose you request "location/ca/sacremento". arg(0) would return "location", arg(1) would return "ca", and arg(2) would return "sacremento".

This might work best with a module-generated page. It *can* work with a node page that contains php, but I don't think url aliases would work that well. It would be better to put this kind of code into a module, anyway.

I don't know much about mod_rewrite. I'm just trying to offer a solution using built-in processes.

- Corey