Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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/$1
</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/$1
</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

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
perfect, thanks! –  ole_berlin Feb 8 '12 at 16:13

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/$1

This means redirect /products/something except something beginning /products/item.

share|improve this answer
    
Thank you, but I don't want to redirect /products/something, I want to redirect /products/ one level deeper to /products/item . Any thoughts on that? –  ole_berlin Feb 8 '12 at 15:36
    
I thought that because you had the (.*) and the $1 in your file. That's what they are there for. In that case Ilmari's answer is what you need. –  paulmorriss Feb 8 '12 at 15:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.