Hello,
I was able to remove "index.php" from the URL, but I am wondering how I can remove "/site/" from the URL. Is this possible?
Also, for static pages, I would like "/site/page?view=about" to instead be "/about". I this possible?
Thanks!
el chief
Hello,
I was able to remove "index.php" from the URL, but I am wondering how I can remove "/site/" from the URL. Is this possible?
Also, for static pages, I would like "/site/page?view=about" to instead be "/about". I this possible?
Thanks!
el chief
You have to enable url manager in main.php , folder protected/config
        'urlManager'=>array(
        	'urlFormat'=>'path',
        	'rules'=>array(
        	          'home'=>'site/index',
        		
        	),
        	'showScriptName'=>false		
        ),
and in main document in htacsess type:
Options +FollowSymLinks
IndexIgnore /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Hello,
Thanks for responding. I tried that and get "Error 404. Unable to resolve the request "about"."
Add the following
                'rules'=>array(
                          'home'=>'site/index',
                          '<view>'=>array('site/page'),
                        
                ),
it will gives us
site/page/about
This should work for you:
'rules'=>array(
    'about'=>'site/about',
    'contact'=>'site/contact',
    '/'=>'site/index',
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
Note, I also include the contact and index page here.
Also add this to your .htaccess:
RewriteRule ^site/about(.*)$ about$1 [R=301,NC,L]
RewriteRule ^site/contact(.*)$ contact$1 [R=301,NC,L]
        Just another note, you will need to change the links in your menu to look like this:
array('label'=>'About', 'url'=>array('/about')),
Edit:
I forgot to mention that to do it exactly as I have mentioned, you will need to have an ‘actionAbout()’ function in your SiteController.php
no he dont need to rewrite , CApplicationComponent do it for you
So… is there a way to rewrite the "static" pages?
yes
eg
array('newrule'=>'site/index')
eg
array('login'=>'site/login')
eg
array('site/dontlogin'=>'site/login')
        Since the view param is required, this is the way to go:
'about' => array('site/page', 'defaultParams' => array('view' => 'about')),
        Are you sure?. Im traying to get this working but if I introduce /about it works but the nav’s link is /site/page/view/about
Thanks.
The suggestions above solve the "/about", but then for others like "/contact", it generates an error 404.
This worked for me:
'urlManager'=>array(
    	'urlFormat'=>'path',
    	'showScriptName'=>false,
    	'rules'=>array(
            	'<view:about>'=>'site/page',
            	'<action:(contact|login|logout|home)>'=>'site/<action>',
            	'<controller:\w+>/<id:\d+>'=>'<controller>/view',
            	'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            	'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    	),
),
In file .htaccess, the basic rewriting is enough:
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
You will then get links like: /index,/about, /contact, /login that work.