Welcome Guest, Not a member yet? Register   Sign In
Page not found - %20 in url
#1

Hi all,

So I'm stumped with this problem and hope someone can help. CI v3.0 is installed in a subdirectory 'api'. 

When I am accessing this URL via CI I get a 404 error - 


Code:
https://someurl.com/api/session_controller/login_redirect/User%20Name/jjfdsiien32


The error in the logs is:
ERROR - 2015-11-16 17:02:52 --> 404 Page Not Found: Api/session_controller

See that Capital A in Api? That's weird right? 

However - this URL works ok:

Code:
https://someurl.com/api/session_controller/login_redirect/UserName/jjfdsiien32

There seems to be an issue that the directory name(!) is getting ucfirst'd when the URL contains the %20 character. 

Here is our .htaccess file (in api dir) - 
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /api/index.php/$1 [L]


Any help on fixing this one would be great. 

Cheers,
Gareth
Reply
#2

In the config file have you updated the base url to include /api ?
Reply
#3

%20 is a space, which means you have a space in the users name [ username ]
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

The ucfirst() on api is not really relevant, it just means that the router went through the whole set of URI segments and couldn't find a route, with api/session_controller being the last thing it checked.

Since the router can't find your route, I'm guessing that UserName is part of the route it's trying to look up (or part of the controller/method pair), and 'User%20Name', 'User Name', and 'UserName' all require different route definitions (or one well-defined RegEx) to work properly. In most cases, I wouldn't consider spaces or %20 worth the time to support in my application, but if you need to do so, you should be able to run through the application with a debugger to make sure you know exactly what is being passed to the router in this instance, then update your route definition accordingly.
Reply
#5

(11-16-2015, 08:23 AM)PaulD Wrote: In the config file have you updated the base url to include /api ?

I've tried both 
PHP Code:
$config['base_url] = "https://someurl.com/api/"; 

and 
PHP Code:
$config['base_url] = ""; 



Neither helps. For some reason CI 3.0 insists on reading in the directory name as part of the URL when a space is present in the URL.
Reply
#6

(11-16-2015, 10:19 AM)mwhitney Wrote: The ucfirst() on api is not really relevant, it just means that the router went through the whole set of URI segments and couldn't find a route, with api/session_controller being the last thing it checked.

Since the router can't find your route, I'm guessing that UserName is part of the route it's trying to look up (or part of the controller/method pair), and 'User%20Name', 'User Name', and 'UserName' all require different route definitions (or one well-defined RegEx) to work properly. In most cases, I wouldn't consider spaces or %20 worth the time to support in my application, but if you need to do so, you should be able to run through the application with a debugger to make sure you know exactly what is being passed to the router in this instance, then update your route definition accordingly.

Ok - so I've added the following route to routes.php: 
PHP Code:
$route['api/session_controller/(:any)/(:any)/(:any)'] = "session_controller/$1/$2/$3"
and it works. Hallelujah. 

However - I still think there is an issue here. I shouldn't have to specify the directory name in the route. This is a hack to get around some kind of internal issue in CI (not that I care right now - its works! yay! thanks mwhitney!). All the other routes look ok without the api prepend. Not to mention that base_url includes 'api/' already.  

CI should know to try the controller first. The problem is that it thinks "api" is a controller when it is obviously not.

There issue has something to do with the space in the parameter name and also perhaps something to do with https.  

IMO routes should only be used when you are doing something clever like renaming your controllers or hiding sub directories etc.
Reply
#7

The base_url setting is not used by either the URI class or the Router class, it is used to generate URLs, not to resolve/route them.

You may need to set $config['uri_protocol'] to 'PATH_INFO' or modify the .htaccess file to set RewriteBase /api/ to get the URI passed to your application to be relative to the /api/ path.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB