Ayaz Alavi
Ayaz Alavi

Reputation: 4835

htaccess more than 9 variables

I am having more than 9 params in my url to be mapped into particular php file. Url is

http://abc.com/USA/NY/male/NY/all-status/all-religion/all-ethnicity/all-cast/all-professions/all-educations/recent_posted

and my htaccess rule is

RewriteRule ^USA/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ search.php?counrty=USA&state=$1&gender=$2&r_city=$3&r_mstatus=$4&r_religion=$5&r_ethnicity=$6&r_cast=$7&r_profession=$8&r_education=$9&sort_by=$10 [NC]

It is not working

Can please anybody sort out this issue? I need proper regex rule and URL

Upvotes: 1

Views: 825

Answers (2)

Lawrence Cherone
Lawrence Cherone

Reputation: 46650

Creating such rule is restricted and bad practice & even worse that your passing the parameters to a search script; As your script progresses your most likely going to want other parameters passed other then USA, meaning your need a new rewrite for each route.

Really you should pass the entire url to your php script to handle the route.

RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/(.*)$ search.php?route=$1 [L,QSA]

This way you can explode('/',$_GET['route']) within your script, giving you an array of all your route parameters.

Upvotes: 6

kalpaitch
kalpaitch

Reputation: 5271

Like Gumbo says, just send the whole lot to the page and process:

$segments = explode('/', $_SERVER['REQUEST_URI']);
    list($country, $state, $gender, [etc etc.]) = $segments;

Upvotes: 3

Related Questions