URL change, SOS rewriterule Regular expression

Source: Internet
Author: User
Because before the Web site feel inadequate specification, so re-adjust the URL, but did not think, Baidu submitted delete URL for a long time, now included or the previous URL, in order not to affect customer access, now want to put the old URL batch redirect to the new URL,
The old format is as follows: http://www.songhuala.com/p1099/Beijing gift/china_flowers_info.html
The new format is as follows: http://www.songhuala.com/-p-1099.html

I did the following redirects in. htaccess,

Rewriteengine on
Rewritecond%{request_uri} ^p/d+\/.*\/china_flowers_info\.html$
Rewriterule ^ (. *) $ ^-p-/d+\.html$1 [r=301,l]

But how can not be directed to the correct new URL, I hope friends can help pointing, I test an afternoon, or did not change the regular expression. Please crossing to enlighten you. Appreciate.


Reply to discussion (solution)

Rewritecond%{request_uri} ^p/d+\/.*\/china_flowers_info\.html$
Rewriterule ^ (. *) $ ^-p-/d+\.html$1 [r=301,l]

The red part seems to be wrong

Rewriteengine on
Rewritebase/
Rewritecond%{request_uri} p (\d+)
Rewriterule p (\d+) http://www.songhuala.com/-p-$1.html [r=permanent,l]

Yesterday was very anxious, has not replied, today to see everyone reply is really very grateful.

After the introduction by asking a friend, asked idreamsoft.com dead wood, solved,
Here's what you can do to complete the redirect.

Rewriteengine on
Rewriterule ^ (. *)? P (\d+). *?\.html$-p-$2\.html [r=301,l]

Rewritecond%{request_uri} ^p/d+\/.*\/china_flowers_info\.html$
Rewriterule ^ (. *) $ ^-p-/d+\.html$1 [r=301,l]

The red part seems to be wrong

Yes, indeed, just learned, anxious also did not pay attention to,, later asked people also found wrong.


Rewriteengine on
Rewritebase/
Rewritecond%{request_uri} p (\d+)
Rewriterule p (\d+) http://www.songhuala.com/-p-$1.html [r=permanent,l]

Well, I think I should be able to, because it's done, I didn't test it. But also let me know that there is such a way of writing.

  • 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.