Javier Villanueva
Javier Villanueva

Reputation: 4058

How to redirect folder without affecting its files in apache?

I have the following rewrite rule in my .htaccess file:

Redirect 301 /products http://example.com/products.html

Which works fine, however it's affecting the URLs of the files inside the folder so:

http://example.com/products/item.html

Gets redirected to:

http://example.com/products.html/item.html

Is there any way that I can only target the parent folder with my redirect and not the files inside it?

Upvotes: 1

Views: 290

Answers (1)

anubhava
anubhava

Reputation: 784998

Is there any way that I can only target the parent folder with my redirect and not the files inside it?

Yes use RedirectMatch for precise targeting using a regex:

RedirectMatch 301 ^/products/?$ http://example.com/products.html

Regex ^/products/?$ will match /product or /product/ but NOT /product/file.

Upvotes: 1

Related Questions