CodeIgniter Forums
URI routing regexp - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: URI routing regexp (/thread-66949.html)



URI routing regexp - timfelix - 12-21-2016

Hi there.
Well I've been enjoying CI for a few years now but I still havent got the hang of using regexp in my URI routing in routes.php
I was hoping for a bit of help if possible.

I am trying to route all requests for URI's that contain another URL.
For example:


http://mysite.com/http://www.google.com
http://mysite.com/www.google.com
http://mysite.com/google.com


the $_SERVER['REQUEST_URI'] would be like:
/http://www.google.com

I was using:
$route['^(http.*|www.*)']
but this doesn't catch the 3rd example

I'm wondering if I should either use one of those very long regexp's that look for a valid url and allow for the proceeding forward slash.

Another idea was to look for a period ('.'), But I didnt want http://mysite.com/file.txt to match.

If anyone could help with this expression I really would be very grateful. I could even send a few dollars. I've been trying to fix this for days (and nights)

-Tim


RE: URI routing regexp - PaulD - 12-21-2016

I posted a couple of links for you on your stack overflow question that 'might' help (although probably not TBH). May I ask why you are trying to deal with such horrible urls? Could you not format the urls to be a bit more useable in some way or are you not in control of them. (Like http://mysite.com/url/google.com)


RE: URI routing regexp - timfelix - 12-21-2016

Hi there.
Thanks for your reply and the links you posted on stack overflow.
Yes, it does seem pretty horrible.
The uri http://mysite.com/www.another site.com is entered by a user into the browser address bar so i cant really change that.
my challenge is how to recognize that a user is adding another url onto the end of my url, regardless of whether they include the http, www, etc.