distortionzzz Posted November 21, 2012 Share Posted November 21, 2012 Hi everyone, I'm going slightly beyond the scope of part 1 of this book. I want to create my own routes, an example being. Instead of /user/register, I want to use just /register. I thought i could just modify the URL Manager config and add something like this: '<action:\w+>'=>'<controller>/<action>', This wouldn't have been an ideal solution anyway incase of duplicate action names. Does anyone have a solution to this. Some kind of override. Thank you. Link to comment Share on other sites More sharing options...
distortionzzz Posted November 21, 2012 Author Share Posted November 21, 2012 Hi again, I can't believe I solved this only minutes after asking for help I simply added the below to the UrlManager 'register'=>'/user/register' And I thought I had to do something fancy Thanks Anyway 1 Link to comment Share on other sites More sharing options...
Larry Posted November 21, 2012 Share Posted November 21, 2012 Yep, that will work. Kudos for figuring it out and thanks for sharing your solution. Link to comment Share on other sites More sharing options...
Solid Posted December 10, 2012 Share Posted December 10, 2012 Thx, nice fix. I was struggeling a bit at first, but then i figured out what i did wrong. You have to remember the / in front of register when you add it to the menu, or it will go to /site/register and fail. You can also add: '/'=>'/site/index' and set the home-link to just /. Thank you Simon Link to comment Share on other sites More sharing options...
Larry Posted December 18, 2012 Share Posted December 18, 2012 I should have mentioned it before, but it should be just: 'register'=>'user/register' You shouldn't need the initial slash. Also, there's really no need to set / to site/index, as site/index is the default controller/action. That's an unnecessary rule, and unnecessary rules confuse things and hurt performance. Link to comment Share on other sites More sharing options...
Edward Posted December 18, 2012 Share Posted December 18, 2012 But a website would look url ugly with site controller after the domain name. So how do we go about this? Link to comment Share on other sites More sharing options...
Antonio Conte Posted December 18, 2012 Share Posted December 18, 2012 It's the main rule. No need to declare it. This is why it works to go to domain.com/index.php or domain.com and still see the default screen. Link to comment Share on other sites More sharing options...
nathor240 Posted January 3, 2013 Share Posted January 3, 2013 Spending hours on trying to gett rid of the index.php in the url. Working on windows maching with XAMPP 1.8.0. and having no luck. Any help would greatly be appreciated. I the url looks good now but I just get a 404 error. I comment out the 'showScriptName'=>false, line in the urlManager config array and the 404 error goes away but the url is messing again. I Checked the httpd.conf file to make sure overrides would be taken from the .htaccess file in the web root. # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All I wrote and saved the htaccess file in the web root where the index.php is, you can see I've tried a few different things. #Options +FollowSymLinks RewriteEngine on #RewriteBase / # if a directory or a file exists, use it directly RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index.php) # otherwise forward it to index.php #RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA] I went in and modified the urlManager array in the main.php config file 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( 'contact' => array('site/contact', 'caseSensitive'=>false), 'login' => array('site/login', 'caseSensitive'=>false), '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ), Link to comment Share on other sites More sharing options...
Larry Posted January 22, 2013 Share Posted January 22, 2013 Sorry. This slipped through the cracks for me. Are you still having a problem with this? Link to comment Share on other sites More sharing options...
Recommended Posts