StackOverflowNewbie
StackOverflowNewbie

Reputation: 40653

CodeIgniter: urlencoded URL in URI segment does not work

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/

Upvotes: 1

Views: 6696

Answers (6)

sun0x0001
sun0x0001

Reputation: 11

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

Upvotes: 1

Vaibhav K
Vaibhav K

Reputation: 388

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.

Upvotes: 0

Diaconescu Doru
Diaconescu Doru

Reputation: 21

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

Upvotes: 0

relipse
relipse

Reputation: 1820

I actually had to do urlencode(urlencode(urlencode(

and urldecode(urldecode(urldecode(

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

Upvotes: 0

MikeCruz13
MikeCruz13

Reputation: 1254

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

Upvotes: 4

Mahavir Munot
Mahavir Munot

Reputation: 1464

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:

Upvotes: 0

Related Questions