1
votes

I'm trying to put a URL as the value of one of my URI segments in CI. My controller method is defined to accept such an argument. However, when I go to the URL, I get a 404 error. For example:

www.domain.com/foo/urlencoded-url/

Any ideas what's wrong? Should I do this via GET instead?

UPDATE:

// URL that generates 404 http://localhost/myapp/profile_manager/confirm_profile_parent_delete/ugpp_533333338/http%3A%2F%2Flocalhost%2Fmyapp%2Fdashboard%2F

// This is in my profile_manager controller public function confirm_profile_parent_delete($encrypted_user_group_profile_parent_id = '', $url_current = '')

If I remove the second URI segement, I don't get a 404: http://localhost/myapp/profile_manager/confirm_profile_parent_delete/ugpp_533333338/

6
Can you post the specific URL and controller code? - Colin Brock
Is the URL the method? or are you set up to leave off the method? Otherwise, try /foo/method/variable i.e. /foo/index/url - MikeCruz13
is the encoded url generating characters that are not allowed in the CI URI? - Laurence

6 Answers

4
votes

It seems that the %2F breaks things for apache.

Possible solutions:

  1. preg_replace the /'s to -'s (or something else) before sending the url then switch it back on the other end.
  2. Set apache to AllowEncodedSlashes On
  3. bit of a hack, but you could even save the url to a session variable or something instead of sending through the url *shrug *
  4. double url encode it before sending
1
votes

Pass urlendode()'d URL in segment and then decode it with own (MY_*) class:

application/core/MY_URI.php:

class MY_URI extends CI_URI {

    function _filter_uri($str)
    {
        return rawurldecode(parent::_filter_uri($str));
    }
}

// EOF
0
votes

You may need to change the rule in config/route.php to accept the encoded characters in URL. Also you can take a look at some of the solution from below articles:

0
votes

I actually had to do urlencode(urlencode(urlencode(

and urldecode(urldecode(urldecode(

3 times!! and it finally worked, twice didn't cut it.

0
votes

try

function __autoload($class){
 if(!empty($_SERVER['REQUEST_URI'])){
  $_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_QUERY_STRING'] = $_SERVER['QUERY_STRING'] = $_SERVER['REDIRECT_URL'] = $_SERVER['argv'][0]  = urldecode($_SERVER['REQUEST_URI']); 
}
}

in config.php this method work for me

0
votes

This is very old, but I thought I'd share my solution.

Instead of accepting the parameter as a url path, accept it as a get variable:

http://localhost/myapp/profile_manager/confirm_profile_parent_delete/ugpp_533333338?url_current=http%3A%2F%2Flocalhost%2Fmyapp%2Fdashboard%2F

and in code:

function confirm_profile_parent_delete($encrypted_user_group_profile_parent_id = '') {
    $url_current = $this->input->get('url_current');
    ...

This seems to work.