Rails beginner
Rails beginner

Reputation: 14514

HTaccess how to redirect multiple URLs?

I want to redirect multiple URLs to the same page.

I could do it this way:

Redirect /index.html http://example.com/newdirectory/
Redirect /index1.html http://example.com/newdirectory/
Redirect /index2.html http://example.com/newdirectory/
Redirect /index3.html http://example.com/newdirectory/
Redirect /index4.html http://example.com/newdirectory/
Redirect /index5.html http://example.com/newdirectory/

Is there not a better method for doing this? (more clean)

Upvotes: 2

Views: 326

Answers (1)

anubhava
anubhava

Reputation: 786261

Yes using RedirectMatch you can use regex in pattern:

RedirectMatch 302 ^/(index|index1|index2|index3|index4|index5)\.html$ http://example.com/newdirectory/

or even more concise:

RedirectMatch 302 ^/index[1-5]?\.html$ http://example.com/newdirectory/

Upvotes: 2

Related Questions