url encoded forward slashes breaking my codeigniter app url encoded forward slashes breaking my codeigniter app codeigniter codeigniter

url encoded forward slashes breaking my codeigniter app


I think the error message you are getting is not from codeigniter but from your web server.

I replicated this using Apache2 without even using CodeIgniter: I created a file index.php, and then accessed index.php/a/b/c - it worked fine. If I then tried to access index.php/a/b/c%2F I got a 404 from Apache.

I solved it by adding to my Apache configuration:

AllowEncodedSlashes On

See the documentation for more information

Once you've done this you might need to fiddle around with $config['permitted_uri_chars'] in codeigniter if it is still not working - you may find the slashes get filtered out


One way to get around this problem would be to replace any forward slashes in your URL variable which you are passing in the URI segments with something that would not break the CodeIgniter URI parser. For example:

$uri = 'example.com/index.html';$pattern = '"/"';$new_uri = preg_replace($pattern, '_', $uri);

This will replace all of your forward slashes with underscores. I'm sure it is similar to what you are doing to encode your forward slashes. Then when retrieving the value on the other page simply use something like the following:

$pattern = '/_/';$old_uri = preg_replace($pattern, '/', $new_uri);

Which will replace all the underscores with forward slashes to get your old URI back. Of course, you'll want to make sure whatever character you use (underscore in this case) will not be present in any of the possible URIs you'll be passing (so you probably won't want to use underscore at all).


With CodeIgniter, the path of the URL corresponds to a controller, a function in the controller, and the parameters to the function.

Your URL, /app/process/example.com/index.html, would correspond to the app.php controller, the process function inside, and two parameters example.com and index.html:

<?phpclass App extends Controller {    function process($a, $b) {       // at this point $a is "example.com" and $b is "index.html"    }}?>

edit: In rereading your question, it seems like you want to interpret part of the URL as another URL. To do this, you need to write your function to take a variable number of arguments. To do this, you can use the functions func_num_args and func_get_arg as follows:

<?phpclass App extends Controller {    function process() {        $url = "";        for ($i = 0; $i < func_num_args(); $i++) {            $url .= func_get_arg($i) . "/";        }        // $url is now the url in the address    }}?>