网址改变,求救RewriteRule 正则表达式

WBOY
Release: 2016-06-23 14:03:25
Original
864 people have browsed it

因为之前网址感觉不够规范,所以重新调整了URL,但是没想到,百度提交删除网址好久了,现在收录还是以前网址,为了不影响客户访问,现在想把旧的URL批量重定向到新的URL,
旧格式如下:http://www.songhuala.com/p1099/北京礼品/China_flowers_info.html
新格式如下:http://www.songhuala.com/-p-1099.html

我在.htaccess 中做了如下重定向,

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

但怎么也定向不到正确新URL来,希望朋友们能帮忙指点下,我测试一个下午,还是没改好这个正则表达式。请各位看官不吝赐教。感激不尽。


回复讨论(解决方案)

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

标红部分似乎有误

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

昨天很着急,一直没答复,今天看到大家回复真是非常感谢。

后面通过问朋友介绍,问到idreamsoft.com 枯木,解决了,
下面是可以完成完成重定向的。

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]

标红部分似乎有误

是的,的确,刚学,着急也没留意,,后面问人也发现错了。


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

恩,这个我看应该可以的,因为弄好了,我没测试。不过还让我了解还有这样的写法。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!