Ask Yii2 's URL rules How to configure a route with ID string format?

Source: Internet
Author: User
Background:
I have opened the URL beautification, here is the current URL rule
Url:
Example.com/site/view?id=06xbvouytbve9ph8t%2fkjg%3d%3d
Where the value of the parameter ID is encrypted

To become this URL:
1, example.com/view/06xbvouytbve9ph8t%2fkjg%3d%3d.html
But no matter how they are configured,
But this is possible:
2, example.com/view/1199.html

2 of these routing rules are well-equipped:

rules => [    'view/
  
   
    
   ' => 'site/view' // 好使]
  
   

But 1 of the routing rules are not good enough to make:

rules => [    'view/
  
   
    
   ' => 'site/view' // 不行    'view/
   
    
     
    ' => 'site/view' // 不行    'view/
    
     
      
     ' => 'site/view' // 不行    '/view/
     
      
       
      .html'=>'site/view?id=
      
       
         ' // 不行] 
       
     
      
    
     
   
    
  
   

Does the rules rule only support \d?
How to configure to have 1 this effect?
Online, etc.

Reply content:

Background:
I have opened the URL beautification, here is the current URL rule
Url:
Example.com/site/view?id=06xbvouytbve9ph8t%2fkjg%3d%3d
Where the value of the parameter ID is encrypted

To become this URL:
1, example.com/view/06xbvouytbve9ph8t%2fkjg%3d%3d.html
But no matter how they are configured,
But this is possible:
2, example.com/view/1199.html

2 of these routing rules are well-equipped:

rules => [    'view/
  
   
    
   ' => 'site/view' // 好使]
  
   

But 1 of the routing rules are not good enough to make:

rules => [    'view/
  
   
    
   ' => 'site/view' // 不行    'view/
   
    
     
    ' => 'site/view' // 不行    'view/
    
     
      
     ' => 'site/view' // 不行    '/view/
     
      
       
      .html'=>'site/view?id=
      
       
         ' // 不行] 
       
     
      
    
     
   
    
  
   

Does the rules rule only support \d?
How to configure to have 1 this effect?
Online, etc.

The upstairs answer makes sense, the appearance%2f means the URL becomes/view/06xbvouytbve9ph8t/fkjg%3d%3d.html, therefore inevitably cannot match/view/ this kind of format.

In addition, the program is very rude to say that it is fooling ghosts. What is the purpose of the friendly URL? Improve readability, help SEO, an unknown so-called encryption string has this role? Is there any difference between the id= and the previously not optimized direct? It's just a formality.

The positive solution is to use the slug field, such as/view/iphone-6s-gold, which is the real optimization.

Do not say that is to prevent other people lose the ID ah, it is untenable, do not want to write more reasons. And the slug solution also solves the problem.

I think,%2f will be treated as/to deal with the ID of the decryption function to outsource a layer, the%2F special processing (such as setting a placeholder instead).

The question is whether 1 or 2.
The title is 2, the content feeling is 1

example.com/view/06XBvOuYTbVE9pH8t%2FKJg%3D%3D.htmlarray(    '/view/
  
   
    
   .html'=>'site/view?id=
   
    
     
    ')
   
    
  
   
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.