nuriye
nuriye

Reputation: 199

Redirect 301 using regexp in .htaccess file

I am looking for a Regex to redirect urls like:

example.net/example-1
example.net/example-2
example.net/example-3

I have many URLs that have the same prefix, but a different suffix after example-.

I was trying around with regex.

Redirect 301 /example-.*$ http://example.net/example-overview
Redirect 301 /example-(.*)? http://example.net/example-overview
Redirect 301 /example-(.+)[/]?$ http://example.net/example-overview
Redirect 301 /([^/example-]+) http://example.net/example-overview

I can't get it work.
Normal redirects for example example-1 to example-overview are working fine.

EDIT: Found a solution:

RedirectMatch 301 ^/example-(.+)[/]?$ http://example.net/example-overview

Upvotes: 1

Views: 208

Answers (1)

msg
msg

Reputation: 8181

Redirect doesn't support regular expressions, use RedirectMatch for that.

Upvotes: 2

Related Questions