N
N
nicoproject2015-11-18 21:33:15
htaccess
nicoproject, 2015-11-18 21:33:15

How to formulate .htaccess 301 redirect (string insertion in URL)?

Woo Commerce for WP uses a specific rewrite base in its URLs For
example:
www.mysite.com/shop/product_cat/product_subcat/product
The Woo website explains that shop cannot be removed, as it can cause serious conflicts.
I need to migrate a site that keeps the results in the index, so I want to set up a 301 redirect in htacess like this:
All requests, except for a certain list (information pages, there are a limited number of them), redirect to identical requests, with an insert /shop/

The question is how to formulate a rule for .htaccess so that
www.mysite.com/product_cat/product_subcat/product
www.mysite.com /shop/ product_cat/product_subcat/product
/product_subcat is an optional part, it may or may not be in the link .

Thanks to

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Chesnokov, 2015-11-19
@cesnokov

RewriteEngine on
RedirectMatch 301 /product_cat/(.*) /shop/product_cat/$1

S
ShamblerR, 2015-11-21
@ShamblerR

RewriteCond %{REQUEST_URI} ^(.*)/dir1/(.*)$
# if string contains /dir1/
RewriteRule ^(.*)$ %1/dir2/%1 [R=301,L]
# Redirect all urls starting from dir1 to dir2 preserving further URL structure

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question