Welcome Guest, Not a member yet? Register   Sign In
routing with encoded forward slash
#1

[eluser]enition[/eluser]
Can any one help me with a work around for this;

I have an external url pointing to a module on my site, this url contains a code for a product part. Problem is that this part contains and encoded forward slash (/), I can get the rout working fine if the code was a proper unencoded slash using one of the following:

Code:
$route['product/(:any)/(:any)'] = "product/lookup/$1--$2";
$route['part/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)'] = "product/lookup/$1--$2";

this works fine with a regular forward slash and as you can see will have to convert the '- -' back to a / inside the module. But as soon as I use / it stops working and I get a 404..

here is an example url that I need to work: http://www.test.com/product/product/one

but i need to pass the 'product/one' as a variable to product/lookup..

any pointers as to how I could achieve this better.. bearing in mind that not all products have the encoded forward slash.

I am rubbish at expressions so go easy Wink

Thanks,
Adam
#2

[eluser]TheFuzzy0ne[/eluser]
Is it the CodeIgniter 404 you're getting or one issued by the server? The reason I ask is that I had problem with encoded slashes, and some servers don't support them by default.
#3

[eluser]enition[/eluser]
I get a regular apache 404 error.. so I guess I need to edit the root .htaccess..?

i get the following:

Code:
Not Found

The requested URL /product/product/one was not found on this server.
#4

[eluser]TheFuzzy0ne[/eluser]
Unfortunately, [url="http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes"]AllowEncodedSlashes[/url] can not be set in the htaccess file. It needs to be set via the apache configuration, or in the vhost file. [url="http://ellislab.com/forums/viewthread/106502/"]I designed a library that allows you to pass data in key-value pairs via the URI[/url], and also allows you to encode slashes and pass the via the URI, and then decode them at the other side of the request. It may or may not be of use to you. Of course, the best option still, is to avoid using encoded slashes completely. Just out of interest, is there any reason you need to use encoded slashes? Can it not be substituted for another character?
#5

[eluser]enition[/eluser]
The product codes are coming from a third party and will not change the encoded slash, their being a bit of a pain tbh Sad

I have turned on AllowEncodedSlashes for the virtual host and i am getting the codeigniter 404 page now Smile
#6

[eluser]enition[/eluser]
Do you know of a cleaner way to do the same as this?

$route['part/([a-zA-Z0-9]+)'] = "product/lookup/$1";
$route['part/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)'] = "product/lookup/$1--$2";
$route['part/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)'] = "product/lookup/$1--$2--$3";
$route['part/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)'] = "product/lookup/$1--$2--$3--$4";

like i said.. rubbish at regular expressions! Sad
#7

[eluser]TheFuzzy0ne[/eluser]
If no-one can help you, I may experiment later on. I have a few ideas, but no time to test them.
#8

[eluser]TheFuzzy0ne[/eluser]
D'oh! Just had a show, and something occurred to me... How many segments present are irrelevant, the are all going to the same controller. So in theory, this one route should do it:
Code:
$route['part/(.+)'] = "product/lookup/$1";

It just grabs everything after part/, and plonks it at the end of the new controller route. I haven't tested it though, but I'm sure it will work, or should be something along those lines.

EDIT: I had a shower, not a show!
#9

[eluser]enition[/eluser]
Thanks for this Smile

Works perfectly, i just impload all the args in the lookup model using a real forward slash as glue and hey presto have the product code!

Big Grin Big Grin
#10

[eluser]TheFuzzy0ne[/eluser]
Always a pleasure, and welcome to the CodeIgniter community! Smile




Theme © iAndrew 2016 - Forum software by © MyBB