Seo problems after qeephp URL beautification

Source: Internet
Author: User

One website operation sectionTimeIn this case, the topic settings may change, which may lead to URL changes. The biggest problem with URL changes is that the previous connection becomes invalid, which has a poor user experience and affects the search engine's indexing of the website. Therefore, we must ensure that the previous URL is not invalid.

For example, previous newsPageThe URL is http://msplinks.com.cn/mdfodhrwoi8vbxkuy29tlzeymzq1ni5odg1s. We can easily deal with this requirement using URL routing.

Write two rules first:

    1. # Parse and generate a new news page url
    2. News_page:
    3. RegEx: '/news/([A-Z] +)/([0-9] +) \. html'
    4. Config:
    5. Category: 1
    6. News_id: 2
    7. Defaults:
    8. Controller: News
    9. Action: Show
    10. # Parse the old news page url
    11. News_page_keep_old:
    12. RegEx: '/([0-9] +) \. html'
    13. Config:
    14. News_id: 1
    15. Defaults:
    16. Controller: News
    17. Action: Show

CopyCode

The preceding rules have a higher priority.

When the requested URL is a http://msplinks.com.cn/MDFodHRwOi8vbXkuY29tLzEyMzQ1Ni5odG1s, the previous rule match fails, and the subsequent rule match succeeds. Therefore, the request is sent to the show action method of the news controller for processing, and the news_id parameter is included.

    1. Function actionshow ()
    2. {
    3. $ News_id = intval ($ _ Get ['news _ id']);
    4. $ News = News: Find ($ news_id)-> get ();
    5. ... Display news content
    6. }

Copy code

This ensures the validity of the original URL.

Then when the request is a http://msplinks.com.cn/MDFodHRwOi8vbXkuY29tL25ld3Mvc3BvcnRzLzEyMzQ1Ni5odG1s, the previous rule will match successfully, then it will not match the subsequent rule. The request is still processed by actionshow. The preceding rule has an additional category parameter, which is not used here. Ignore it directly. However, this parameter is indispensable and will be used for subsequent URL generation.

Now let's take a look at the url generation code in the template:

    1. URL ('news/show', array (
    2. 'News _ id' => $ news-> ID,
    3. 'Category '=> $ news-> category_name
    4. ))

Copy code

We can see that the category parameter is used to generate a URL. Therefore, the preceding rule is used to generate a URL. Eventually we will get results like http://msplinks.com.cn/MDFodHRwOi8vbXkuY29tL25ld3MvY2Fycy8yMzM0My5odG1s.

Now we have solved the problem perfectly: it not only ensures the validity of the previous URL, but also makesAccessAfter accessing the old page, you can navigate to the new format URL through the URL in the page.

--------------------------------------

URL changes as needed

In addition to Seo, URL routing also allows us to construct URL addresses as we like. For example, the URL rule for http://msplinks.com.cn/MDFodHRwOi8vcWVlcGhwLmNvbS9jYXNlcy8xOQ== is:

    1. Cases_show:
    2. Pattern: "/cases/: ID"
    3. Defaults:
    4. Controller: "cases"
    5. Action: "show"
    6. Config:
    7. ID: "[0-9] +"

Copy code

We changed the rule:

    1. Cases_show:
    2. RegEx: '/mygod/show \-me \-the \-money/news \-sports \-(\ D +) \. html'
    3. Defaults:
    4. Controller: "cases"
    5. Action: "show"
    6. Config:
    7. ID: 1

Copy code

Then the URL becomes the http://msplinks.com.cn/MDFodHRwOi8vcWVlcGhwLmNvbS9teWdvZC9zaG93LW1lLXRoZS1tb25leS9uZXdzLXNwb3J0LTE5Lmh0bWw=. It can be said that it is similar to the previous URL.

These modifications and changes do not require us to modify the application.ProgramIn the code and template code, the only thing that needs to be modified is the rule table.

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.