ok1ha
ok1ha

Reputation: 637

.htaccess Redirect Pattern

I'm looking to redirect the pattern of a letter and up to two numbers (a12,d17) to (/home#d17, /home#a12).

There will be around 60 of these redirects so I was hoping a pattern could make things easier. Any ideas?

Redirect 301 /a1 /home#a1
Redirect 301 /d13 /home#d13

Upvotes: 2

Views: 3214

Answers (2)

HamZa
HamZa

Reputation: 14921

Try the following:
Redirect 301 /([a-z][0-9]{1,2})$ /home#$1

  • ( : start of capturing group 1
  • [a-z] : match a letter (lowercase)
  • [0-9]{1,2} : match one or two digits
  • ) : end of capturing group 1
  • $ : end of line

We'll use $1 to reffer to group 1.

Upvotes: 4

Lucas Willems
Lucas Willems

Reputation: 7063

Try this htaccess code :

RewriteEngine On
RewriteRule ^([a-z0-9])$ /home#$1 [R=301]

Upvotes: 1

Related Questions