3

After redoing my webshop, I need to redirect every URL within a certain directoy to a new page.

All URLs beginning ith example.com/shop/... should be redirected to the page located at example.com/products/.

I'm using this wordpress plugin for redirections, but I don't know if it can handle it or I need to edit the htaccess file or something.

.htaccess:

# 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]
RewriteRule ^shop/ /products/ [R=302,L]
</IfModule>

# END WordPress

1 Answer 1

2

That WordPress plugin should be able to handle this, but otherwise it's just a one-liner in .htaccess (which will also be more efficient):

RewriteRule ^shop/ /products/ [R=302,L]

The above directive should go after the RewriteEngine and RewriteBase directives but before any other WordPress stuff.

This redirects /shop/<anything> to /products/.

Change the 302 (temporary) redirect to 301 (permanent) when you are sure it's working OK. Temporary redirects are easier to test since they are not cached by the browser.

9
  • It shouldn't redirect /shop/<something> to /products/<something>, it should redirect /shop/<something>` to `/products/
    – ReddaJoppe
    Commented Feb 17, 2016 at 12:37
  • How would you suggest I handle it with the plugin? Redirecting from /shop/(.*)doesn't seem to work - what do I need to type?
    – ReddaJoppe
    Commented Feb 17, 2016 at 12:40
  • I've updated my answer. Unfortunately I'm not familiar with that plugin.
    – MrWhite
    Commented Feb 17, 2016 at 12:41
  • OK, thanks. Can you explain why you are sugesting a 302 redirect and not 301?
    – ReddaJoppe
    Commented Feb 17, 2016 at 12:43
  • 1
    Sorry, I guess I didn't read your answer closely enough. It works perfect, thank you.
    – ReddaJoppe
    Commented Feb 17, 2016 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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