How to make redirect 301 from ulr: https://domen.com/some-word/* to https://domen.com/products/some-word/* using .htaccess
make 301 redirect from one url to another
RewriteEngine on
# RewriteCond %{ENV:HTTPS} !on
# RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
how i can to resolve this problem?
2
Answers
Requests that start with
/some-word/
can be matches usingRewriteCond
and then redirected withRewriteRule
that prepends the/products
to%{REQUEST_URI}
:Make sure to put this at the top of your
.htaccess
, otherwise it might not work because of the other rules.You don’t need to use mod_rewrite for such a redirect (unless perhaps you are already using mod_rewrite for other rules). A simple mod_alias
Redirect
directive would suffice.For example:
The
Redirect
directive is prefix-matching and everything after the match is copied onto the end of the target. So,/some-word/foo
would be redirected to/products/some-word/foo
by the above rule.Reference: