CodeIgniter Forums
Routes matching regex help... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Routes matching regex help... (/showthread.php?tid=29999)



Routes matching regex help... - El Forum - 04-29-2010

[eluser]mrreece[/eluser]
I'm new to forum, so "hello everybody" Smile

I need some help with routing specific matches in the url. Regular expression aren't my greatest strength, so i'd really appreciate any help if you have some free time.

The problem is as follows:

I get "too curious" visitors who seem to think for some reason that my site is joomla based :gulp:
So i'm getting allot of 404's for joomla related manually typed urls.
I would like to be able to route them to a specific controller Wink

For the moment I've put every match so far as a seperate rewrite rule:

$route[‘administrator/index.php’] = “nojoomla”;
$route[‘joomla/administrator/index.php’] = “nojoomla”;
$route[‘joomla1.5/administrator/index.php’] = “nojoomla”;
$route[‘joomla15/administrator/index.php’] = “nojoomla”;
$route[‘joomla2/administrator/index.php’] = “nojoomla”;
$route[‘joomla1/administrator/index.php’] = “nojoomla”;
$route[‘Site/administrator/index.php’] = “nojoomla”;
$route[‘site_old/administrator/index.php’] = “nojoomla”;
$route[‘cms_old/administrator/index.php’] = “nojoomla”;
$route[‘joomla_old/administrator/index.php’] = “nojoomla”

... & ect, they're 30+ so far.

How exactly can I write a single rule that will match strings like "joomla, administrator, Site, joomla_old & ect" in the controller and method aswell ?

Thanks in advance!


Routes matching regex help... - El Forum - 04-29-2010

[eluser]mddd[/eluser]
I think anyone (probably a lot of them aren't even real people but robots trying to hack your site) who tries to do this, is up to no good.
Just let them have the 404 and be done with them.


Routes matching regex help... - El Forum - 04-29-2010

[eluser]mrreece[/eluser]
Yah, probably, but still, i'd like to send them to a controller and have it do a record of the "visitor's" details.


Routes matching regex help... - El Forum - 04-29-2010

[eluser]mddd[/eluser]
Well, it's up to you of course!
If you want to check for strings, you can use wildcards in your regexes/routes.

I don't know much aboot joomla, but I see that all your url's end in administrator/index.php.
So I would suggest this route:

$route['(.*)administrator/index\.php'] = “nojoomla”;

It will send any url ending with 'administrator/index.php' to your controller.


Routes matching regex help... - El Forum - 04-29-2010

[eluser]mrreece[/eluser]
Ahaaa, right.

So basicly if I wanted to match a string anywhere in the url, would this be correct ?:

$route[’(.*)administrator(.*)’] = “nojoomla”;


Routes matching regex help... - El Forum - 04-29-2010

[eluser]mddd[/eluser]
Yes.


Routes matching regex help... - El Forum - 04-29-2010

[eluser]mrreece[/eluser]
Wonderful :coolsmile:

Thanks very much for you help !