outrage  
          
              
                March 7, 2013, 10:07pm
               
              2 
           
         
        
          Add this to url manager:
'urlSuffix' => '/',
I’m sure you can work out the canonical part.
A friendly tip…
Personally I hate it when people ask questions and then say it’s urgent. I do this in my free time for no pay and don’t give a damn how urgent somebody else’s project is. I consider it disrespectful imho.
         
        
           
         
            
       
      
        
        
          Thanks. It is now generating urls with "/" in end but if someone requests a url without "/" in end then it should redirect to the "/" version. How to do this redirection?
 outrage:
 
Add this to url manager:
'urlSuffix' => '/',
I’m sure you can work out the canonical part.
A friendly tip…
Personally I hate it when people ask questions and then say it’s urgent. I do this in my free time for no pay and don’t give a damn how urgent somebody else’s project is. I consider it disrespectful imho.
 
 
         
        
           
         
            
       
      
        
          
          
            jacmoe  
          
              
                March 7, 2013, 10:13pm
               
              4 
           
         
        
        
           
         
            
       
      
        
        
          I already checked that page. I don’t understand all the htaccess code perfectly. Therefore when I used the code from that url it also didn’t worked for me.
Here is my .htaccess file
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
Now please tell me what should I modify?
         
        
           
         
            
       
      
        
          
          
            jacmoe  
          
              
                March 7, 2013, 10:27pm
               
              6 
           
         
        
          
htaccess rules are tricky. So just try.
It’s a valuable skill to acquire.
         
        
           
         
            
       
      
        
          
          
            outrage  
          
              
                March 7, 2013, 10:41pm
               
              7 
           
         
        
          As Jacmoe says…
Keep up your search on htaccess until you find something appropriate.
It’s not Yii specific and you might find it doesn’t work well on localhost with root in a sub-folder anyway.
It’s kind of a “suck and see” kind of thing specific to your situation.
         
        
           
         
            
       
      
        
        
          Hi,
I ended up with this solution:
I placed this code in global controller class constructor(i.e. the class from which all controller classes extend)
$slash = substr($this->request->url, -1);
$url = $this->request->hostInfo.$this->request->url;
if($slash != "/"){
 $this->redirect($this->request->url."/",true,301);
$url = $this->request->hostInfo.$this->request->url."/";
}
Yii::app()->getClientScript()->registerLinkTag("canonical",null,$url);
 outrage:
 
As Jacmoe says…
Keep up your search on htaccess until you find something appropriate.
It’s not Yii specific and you might find it doesn’t work well on localhost with root in a sub-folder anyway.
It’s kind of a “suck and see” kind of thing specific to your situation.