user1155594
user1155594

Reputation: 315

How to redirect a directory path to a single file

https://example.com/folder/ needs to direct to https://example.com/folder.html

I added this to the htaccess,

Redirect 301 /folder https://example.com/folder.html

This works if the url is https://example.com/folder

However if the url is https://example.com/folder/ then it redirects to a broken url at https://example.com/folder.html/

How would I fix this so that https://example.com/folder/ redirects to https://example.com/folder.html/ without the trailing slash causing it to break?

Upvotes: 1

Views: 420

Answers (1)

anubhava
anubhava

Reputation: 785266

Better to use a RedirectMatch rule that supports regex with more powerful matching options:

RedirectMatch 301 ^/folder/?$ /folder.html

Make sure to test it in a new browser or clear browser cache before testing.

Upvotes: 1

Related Questions