Redirect all pages within subdirectory to new page
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, redirects, wordpress, mod-rewrite, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :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
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.
Comments
Post a Comment