Daniel Harris
Daniel Harris

Reputation: 1905

htaccess regex redirecting

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]

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

Upvotes: 1

Views: 49

Answers (1)

Mike Rockétt
Mike Rockétt

Reputation: 9007

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

Use ([0-9]+) instead of [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]

Upvotes: 1

Related Questions