How to configure a route entry whose id is in string format in urlrules of yii2?

Source: Internet
Author: User
Background: I have enabled url Beautification. The following is the current url rule URL: example. comsiteview? Id06XBvOuYTbVE9pH8t % 2 FKJg % 3D % 3D where the parameter id value is encrypted and you want to change it to this url: 1. example. comview06XBvOuYTbVE9pH8t % 2 FKJg % 3D % 3D. h... background:
I have enabled url Beautification. The following are the current url rules.
URL:
Example.com/site/view? Id = 06XBvOuYTbVE9pH8t % 2 FKJg % 3D % 3D
The value of the parameter id is encrypted.

To change to this url:
1. example.com/view/06XBvOuYTbVE9pH8t%2FKJg%3D%3D.html
However, no matter how configured,
However, this is acceptable:
2. example.com/view/1199.html

The routing rules of 2 are well configured:

Rules => ['view/
  
   
'=> 'Site/view' // Easy to use]
  

However, the configuration of the 1 route rule is not good:

Rules => ['view/
  
   
'=> 'Site/view' // no 'View/
   
    
'=> 'Site/view' // no 'View/
    
     
'=> 'Site/view' // No'/view/
     
      
. Html '=> 'site/view? Id =
      
        '// No]
      
     
    
   
  

Does the rules rule only support the \ d regular expression?
How can I configure it to achieve the effect of 1?
Online

Reply content:

Background:
I have enabled url Beautification. The following are the current url rules.
URL:
Example.com/site/view? Id = 06XBvOuYTbVE9pH8t % 2 FKJg % 3D % 3D
The value of the parameter id is encrypted.

To change to this url:
1. example.com/view/06XBvOuYTbVE9pH8t%2FKJg%3D%3D.html
However, no matter how configured,
However, this is acceptable:
2. example.com/view/1199.html

The routing rules of 2 are well configured:

Rules => ['view/
  
   
'=> 'Site/view' // Easy to use]
  

However, the configuration of the 1 route rule is not good:

Rules => ['view/
  
   
'=> 'Site/view' // no 'View/
   
    
'=> 'Site/view' // no 'View/
    
     
'=> 'Site/view' // No'/view/
     
      
. Html '=> 'site/view? Id =
      
        '// No]
      
     
    
   
  

Does the rules rule only support the \ d regular expression?
How can I configure it to achieve the effect of 1?
Online

The answer upstairs makes sense. If % 2F appears, it means that the url is/view/06XBvOuYTbVE9pH8t/fkjg1_3d1_3d.html, so it cannot match/view/ This format is used.

In addition, this solution is just a fool. What is the purpose of Friendly URL? Improve readability and help SEO. does an unknown encrypted string play this role? Is it direct to the previous optimization? Is there any difference in id =? It's just a form. interesting?

The positive solution is to use slug fields such as/view/iphone-6s-gold, which is truly optimized.

Don't say it is to prevent others from losing their IDs. this is untenable and you don't want to write more reasons. The slug solution also solves this problem.

In my opinion, % 2F will be treated as/. you can outsource a layer of id encryption and decryption functions and perform special processing on % 2F (such as setting a placeholder instead ).

Whether it is question 1 or question 2.
Title is 2, content is 1

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

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.