el_chief
(el chief)
December 7, 2010, 10:31pm
1
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
iivano71
(Igor Zg1987)
December 7, 2010, 10:39pm
2
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
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
el_chief
(el chief)
December 7, 2010, 11:46pm
3
Hello,
Thanks for responding. I tried that and get "Error 404. Unable to resolve the request "about"."
perochak
(Amjad Mughal)
December 8, 2010, 6:04am
4
Add the following
'rules'=>array(
'home'=>'site/index',
'<view>'=>array('site/page'),
),
it will gives us
site/page/about
outrage
(Site Sense Web)
December 8, 2010, 4:55pm
5
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]
outrage
(Site Sense Web)
December 8, 2010, 6:43pm
6
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
iivano71
(Igor Zg1987)
December 8, 2010, 11:03pm
7
no he dont need to rewrite , CApplicationComponent do it for you
dimvic7
(Dimitris Vic)
August 2, 2011, 9:27pm
8
So… is there a way to rewrite the "static" pages?
iivano71
(Igor Zg1987)
August 3, 2011, 8:42am
9
yes
eg
array('newrule'=>'site/index')
eg
array('login'=>'site/login')
eg
array('site/dontlogin'=>'site/login')
Y11
(Y!!)
August 3, 2011, 9:00am
10
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.
rabb21
(Box)
November 20, 2013, 11:40am
12
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.