Sure that it’s not a 404? And who’s throwing the error? The webserver (indicating that mod_rewrite doesn’t work) or Yii (indicating that your URL rules still aren’t right).
this error message i am getting after implementing this rule…mod_rewrite is working fine on my webserver excluding this all the rules which i define is working correctly…
The rule ‘/<_a>’=>‘page/<_a>’ is already matching anything, so put this rule as last rule
Your regular expression seems strange: name and id both can contain letters + numbers. So how should Yii know, where a name ends and the id starts? You should maybe use a different URL schema and put a / between them (/johnny/24).
it sometimes throws 404 exception even if I put all the rules before it…
My next solution is to create a new behaviour to handle request processing in the application,
it uses the application’s catchAllRequest property (since I rarely use it )
<?php
class UsernameURLBehaviour extends CBehavior {
public function attach($owner) {
// set the event callback
$owner->attachEventHandler('onBeginRequest', array($this, 'beginRequest'));
}
/**
* This method is attached to the 'onBeginRequest' event above.
* */
public function beginRequest(CEvent $event) {
$route = Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest());
$exists = User::model()->exists('username = :username', array(':username' => $route));
if ($exists && !is_array($event->sender->catchAllRequest)) {//if the route exists in username
//catch all request to profile/view
$event->sender->catchAllRequest = array(
'profile/view',
'username' => $route,
);
}
}
}
then in the controller ProfileController just load the username from $_GET[‘username’] or you could preload the model at the UsernameURLBehaviour and then save it
works like charm for me
well, one of the setback is to make a username blacklist so user couldn’t register with a username similar with one of your controller’s name
thanks petra for you reply on my post…but mike’s suggestion put me near to my solution…so i’ll prefer his suggestion at this moment…but your approach is also good.
I’m sorry, i don’t understand. If you don’t want id in your URL, then why do you have it in the rule? You should then only use
[color="#1C2837"][size="2"]
'<name:[a-zA-Z0-9_-]+>'=>'user/publicprofile',
[/size][/color]
[color="#1C2837"] [/color][color="#1C2837"][size="2"]Maybe your problem is that you also have this rule (as you showed above):[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"][size="3"]
'/<_a>'=>'page/<_a>',
[/size][/size][/color]
[color="#1C2837"][size=“2”] [/size][/color][color="#1C2837"]If you do have such a rule, then you’re out of luck: Both rules match anything, so how should Yii know, which rule should apply if a URL matches both? It will always use the first matching rule in this case.[/color]
yes, i think you are saying right.now i am not passing argument two in link…just change code of my action this time.
and i also remove
[color="#1C2837"][size="2"][size="3"]
'/<_a>'=>'page/<_a>',
[/size][/size][/color]
this code from my rules. now everything is working fine as i want. but my page controller actions are not working same as before.but thats not a big deal.i’ll manage it it.
the main issue was that to create a url like that format and yes it is…so i just want to give a thanks for your support and help mike…once again Yii prove that YES IT IS RIGHT…
thanks again mike…!!! see you on some another forum topic…!!