Search code examples
asp.neturl-rewritingisapi-rewrite

Create redirect for all pages in a subdirectory


So far I've been setting up redirects for single pages on my ASP.NET site using ISAPI_REWRITE. These work perfectly well (example below):

# Redirect
RewriteCond %{HTTP:Host} ^(?:www\.)?example\.com$
RewriteRule ^/category-1/products\.aspx /category-2/products\.aspx [I, R=301]

This will redirect www.example.com/category-1/products.aspx to www.example.com/category-2/products.aspx.

However, now I want to rewrite this so that ALL requests to a page within category-1 redirect to the identical page on category-2, i.e. www.example.com/category-1/allpages.aspx to www.example.com/category-1/allpages.aspx.

How do I go about this with the RewriteRule?


Solution

  • Try with this

    # Redirect
    RewriteCond %{HTTP:Host} ^(?:www\.)?example\.com$
    RewriteRule ^/category-1/(.*) /category-2/$1 [I, R=301]