: Htaccess 301 redirect subdirectory one level deeper - why is this not working? it is probably a stupid question, but I have real troubles figuring out, how to redirect /products to /products/item
it is probably a stupid question, but I have real troubles figuring out, how to redirect
/products to /products/item
It is a simple redirect, no regex needed. The toplevel site /products should just always redirect to /products/item
I tried:
<IfModule mod_rewrite.c>
RedirectMatch 301 /products(.*) /products/item/
</IfModule>
I receive the error, that the webserver is redirecting in an infinite loop. That might be because of the rest of the htaccess file. Which looks like that:
# Custom Rules
<IfModule mod_rewrite.c>
RedirectMatch 301 /products(.*) /products/item/
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
But the strangest thing: When I load the page, I get the error. When I then hit reload, it works???
Thanks for your help!
ole
More posts by @Jessie594
2 Comments
Sorted by latest first Latest Oldest Best
If you just want to redirect /products to /products/item, this should work:
RedirectMatch 301 ^/products/?$ /products/item
The ^ and $ characters anchor the regular expression to the beginning and end of the path, so that it won't match /foo/products or /products/bar. The /? allows it to match both /products and /products/; you can remove it if you don't want that.
The (.*) after products is what's causing the loop. It redirects
/products/something to /products/item/something, but then that has to be redirected to /products/item/item/something etc.
You need to exclude item so this may work:
RedirectMatch 301 /products/(?!^item)(.*) /products/item/
This means redirect /products/something except something beginning /products/item.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.