URL changed. for help, RewriteRule regular expression

Source: Internet
Author: User
The website address changed. for help, the RewriteRule regular expression was changed because the previous website address was not properly configured. However, I did not expect that Baidu submitted and deleted the website for a long time. now it is still the previous website address, in order not to affect customer access, we want to batch redirect old URLs to new URLs,
The old format is as follows: http://www.songhuala.com/p1099/beijing gift /china_flowers_info.html
New format: http://www.songhuala.com/-p-1099.html

I made the following redirection in. htaccess,

RewriteEngine on
RewriteCond % {REQUEST_URI} ^ p/d + \/. * \/China_flowers_info \. html $
RewriteRule ^ (. *) $ ^-p-/d + \. html $1 [R = 301, L]

However, the correct new URL cannot be targeted. I hope my friends can help me to test this regular expression for one afternoon. Thank you for your patience. Grateful.


Reply to discussion (solution)

RewriteCond % {REQUEST_URI} ^ p/d + \/. * \/China_flowers_info \. html $
RewriteRule ^ (. *) $ ^-p-/d + \. html $1 [R = 301, L]

The marked red part seems to be incorrect.

RewriteEngine On
RewriteBase/
RewriteCond % {REQUEST_URI} p (\ d +)
RewriteRule p (\ d +) http://www.songhuala.com/-p-00001.html [R = permanent, L]

I was in a hurry yesterday and never replied. thank you very much for your reply today.

Later, I asked my friend about idreamsoft.com to solve the problem,
The following describes how to complete redirection.

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 marked red part seems to be incorrect.

Yes. I did not pay attention to it when I was just learning it. I also found a mistake when asked later.


RewriteEngine On
RewriteBase/
RewriteCond % {REQUEST_URI} p (\ d +)
RewriteRule p (\ d +) http://www.songhuala.com/-p-00001.html [R = permanent, L]

Well, I think it's okay, because I did not test it. However, it also helps me understand such a statement.

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.