urlManager

Hi guys

I m trying to learn how to make url’s more readable. To start with I am going to change


 http://localhost/user/index.php?r=user/create 

to


 http://localhost/user/create

and in config/main.php:




'components'=>array(

		'urlManager'=>array(

            		'urlFormat'=>'path',

            		'rules'=>array('user/index.php?r=user/create'=>'/create')

            		),

...................




I know it is not correct but how I can fix it?

Later I am going to fix the URL for all CRUD functions and Mange/List links

Thank you

Typed freehand, but it should work:




'urlManager'=>array(

    'urlFormat'=>'path',

    'rules'=>array(

        'create'=>'user/create',

    ),

),



Thank you but it gave me


 http://localhost/user/index.php/create 

I would rather to get me


http://localhost/user/create

Notice index.php is removed

Ah, sorry. i misunderstood what you really wanted :lol: Here we go:




'urlManager'=>array(

    'urlFormat'=>'path',

    'showScriptName'=>false,

    'rules'=>array(

        ...

    ),

),



Don’t forget to set a .htaccess in place or you’ll end up in 404s.

I am afraid that i have no idea about that file !!

Hint: The Definite Guide to Yii is always a valuable source of information.

http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x

I am using XAMPP on Mac but I couldnt find .htaccess file. Any hint?

Thank you

If it isn’t there, you need to create it. Preferebly in your webroot.

Simple


 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



did not actually do anything for me

I dont know why but I had the showScriptName inside the rules array. I just had to placed it before rules array and it works now :)




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



i use this. works nice)

Worked for me too on Mac using XAMPP but I am trying to do the same thing on IIS on windows machines.

Any idea how clean url works on windows machine running IIS?

Not really. But it has to look similar to what is being described here.

I decided not work with IIS and rewrite rules. I installed XAMPP and using Apache but I really dont know why the same urlManager is not working.

I copied everything too XAMPP\htdocs.

What did I do wrong?

Thank you