htaccess的正则表达式重定向 [英] htaccess regex redirecting

查看:136
本文介绍了htaccess的正则表达式重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过700的所有使用规则集重定向在htaccess文件。我无法搞清楚如何重定向多个页面的URL数字2-20。这里是我的非工作重定向:

I have over 700 redirects in a htaccess file all using RewriteRules. I'm having trouble figuring out how to redirect multiple pages with numbers 2-20 in the URL. Here are my non-working redirects:

RewriteRule ^orlando-airport/americas-best-cocoa-beach/1-person-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/americas-best-cocoa/1-person [R=301,L]
RewriteRule ^orlando-airport/americas-best-cocoa-beach/[0-9]-people-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/americas-best-cocoa/$1-people [R=301,L]
RewriteRule ^orlando-airport/double-tree-cocoa-beach/1-person-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/doubletree-cocoa-beach/1-person [R=301,L]
RewriteRule ^orlando-airport/double-tree-cocoa-beach/[0-9]-people-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/doubletree-cocoa-beach/$1-people [R=301,L]

线1和3的工作,但2和4没有。人在网址的数量应为1人,然后2-20人。任何帮助将是AP preciated

Lines 1 and 3 work but 2 and 4 don't. The number of people in the URLs should be 1 person and then 2-20 people. Any help would be appreciated

推荐答案

你没有捕捉前pression,而你只允许一个数字。

You're not capturing the expression, and you're only allowing one digit.

使用([0-9] +)而不是 [0-9]

RewriteRule ^orlando-airport/americas-best-cocoa-beach/1-person-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/americas-best-cocoa/1-person [R=301,L]
RewriteRule ^orlando-airport/americas-best-cocoa-beach/([0-9]+)-people-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/americas-best-cocoa/$1-people [R=301,L]
RewriteRule ^orlando-airport/double-tree-cocoa-beach/1-person-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/doubletree-cocoa-beach/1-person [R=301,L]
RewriteRule ^orlando-airport/double-tree-cocoa-beach/([0-9]+)-people-fly-snooze-cruise-hotel-package.html$ /fly-snooze-cruise/orlando-airport/doubletree-cocoa-beach/$1-people [R=301,L]

这篇关于htaccess的正则表达式重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆