CUrlManager problem

I have a problem and I dont know that is bug or maybe I do something wrong.

this is my urlmanager config


'urlManager'=>array(

'urlFormat'=>'path',

'showScriptName'=> false,

'routeVar'=>'yr',

),

and now I prepare url

example


http://host/controllerID/actionID/param1/value1

and value1 (abc%2Fabc) contains %2F, its encoded ‘/’

if I try open this url I have exception (server error 404 not yii exception)

Maybe someone could explain me how I can pass this variable (/) in url.

thanks

Have you setup your .htaccess file to rewrite the URL?

Check out : http://www.yiiframework.com/doc/guide/topics.url

its my htaccess configuration (its default configuration)


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php

Possible reasons:

  • your webserver is not Apache -> Find out what to use instead of mod_rewrite

  • your webserver doesn’t have mod_rewrite -> Try to enable/install that module

  • your webserver doesn’t read .htaccess files -> Add a AllowOverride All for your webroot directory in your Apache conf.

My server version is Apache/2.2.12, mod_rewrite module is enabled

this is a part my apache.conf


<VirtualHost 192.168.2.37:80>

        ServerAdmin webmaster@localhost

        ServerName localhost

        DocumentRoot /home/xxx/public_html

        ErrorLog /var/log/apache2/error.log


        LogLevel warn


        CustomLog /var/log/apache2/access.log combined


        <Directory /home/xxx/public_html/>

            Options Indexes FollowSymLinks MultiViews

            [b]AllowOverride All[/b]

            Order allow,deny

            allow from all

        </Directory>

</VirtualHost>

I know that is not Yii problem, but I dont understand it and cant explain.

When I use ‘/’ char after ‘?’ char url is reading like I expect,

but when url has ‘path’ format


http://url/context/param_key/abc%2Fabc

then param_key/abc%2Fabc is including to context part, and server try find


http://url/context/param_key/abc/abc

(this context doesnt exit in my app)

Try to add this to your vhost config:


AllowEncodedSlashes On

By default most Apache installations give a "404 Not found" if a URL contains a %2F.

thnaks, it works but its only part of solution ;)

Now server redirect this request to index.php properly,

but Yii urlManager handle this request incorrect.

I have url rule


'/test/<var>'=>'test/index',

and in my IndexAction i have




class IndexAction extends CAction {

  public function run() {

    CVarDumper::dump($_GET,3,true);

  }

}



First case, I try open url


http://192.168.2.37/test/beggin%2Fend

and Yii throws exception




The system is unable to find the requested action [b]"beggin"[/b].



In this case beggin%2Fend should be value of var.

Second case, I try open


http://192.168.2.37/test/index/var/beggin%2Fend

Yii properly opens test/index action, and my dump shows




array

(

    [var] => 'beggin'

    [end] => ''

) 



This is a part of function parseUrl from class CUrlManager (Yii Framework)




	public function parseUrl($request)

	{

		if($this->getUrlFormat()===self::PATH_FORMAT)

		{

			$rawPathInfo=urldecode($request->getPathInfo());

			$pathInfo=$this->removeUrlSuffix($rawPathInfo,$this->urlSuffix);

			foreach($this->_rules as $rule)

			{

				if(($r=$rule->parseUrl($this,$request,$pathInfo,$rawPathInfo))!==false)

					return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r;

			}



this function firstly use of urldecode function on whole path and next reads rules from path,

its a bug or it should works that???

I fix this problem, I build my url in different way.

I dont use variables keys in my url rules, but its not a solution!

Maybe you’re right. But not sure, why urldecode is used here but it’s surely there for a reason. Maybe also check CUrlRule::parseUrl() to find out more.

Same error here. Confirm this is a bug… Or we don’t get something? :)