Donnie D'Amato
Donnie D'Amato

Reputation: 3940

htaccess rewrite using fake directory as params

I've tried doing a lot of research on this but nothing I seem to do works so I'm coming here for help. I'm trying to do the following:

request: /rss/40.6,-73.4

rewrite: /php/autoFeed.php?coords=40.6,-73.4

My regex that matches the coords is ^\/rss\/([\-]?\d+\.\d{1},[\-]?\d+\.\d{1})$ though I understand I don't need to escape the directory slashes. That still didn't work:

RewriteEngine On
RewriteRule ^/rss/([\-]?\d+\.\d{1},[\-]?\d+\.\d{1})$ /php/autoFeed.php?coords=$1 [NC, L]

Do I need a RewriteCond?

Upvotes: 2

Views: 49

Answers (1)

anubhava
anubhava

Reputation: 785226

You can just simplify your regex and rule to:

RewriteEngine On

RewriteRule ^rss/([^/]+)/?$ /php/autoFeed.php?coords=$1 [NC,QSA,L]

For precise matching you can use:

RewriteRule ^rss/(-?\d+\.\d+,-?\d+\.\d+)/?$ /php/autoFeed.php?coords=$1 [NC,QSA,L]

Upvotes: 1

Related Questions