Sohail Anwar
Sohail Anwar

Reputation: 304

Forcing Routing in codeigniter using regex

i have following route in route.php in codeigniter

$route['^(?!login|signup|autos|jobs|jobwanted|admin).*'] = "pages/bpages"; 

it is redirecting everthing to pages/bpages except (login|signup|autos|jobs|jobwanted|admin )

eg www.mysite.com/sohailanwarpk

as sohailanwapk is not in (autos|jobs|jobwanted|admin) it will redirected to pages/bpages the problem i am facing is in that condition if my url is like

eg www.mysite.com/autosss

eg www.mysite.com/jobs123

it should direct autosss or jobs123 to "pages/bpages"; but its not,so how can i exaclty match (autos|jobs|jobwanted|admin) so that everything else will be redirected.

Upvotes: 0

Views: 134

Answers (2)

Rocco
Rocco

Reputation: 1085

Split it into 2 routes:

$route['^(?!(login|signup|autos|jobs|jobwanted|admin)).*']  = "pages/bpages";
$route['^(login|signup|autos|jobs|jobwanted|admin)[^\/].*'] = "pages/bpages";

Upvotes: 1

Victor
Victor

Reputation: 5769

Just write 2 rules:

$route['^(login|signup|autos|jobs|jobwanted|admin)$'] = '$1';
$route['(:any)'] = 'pages/bpages';

Upvotes: 0

Related Questions