skip to Main Content

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


  1. Requests that start with /some-word/ can be matches using RewriteCond and then redirected with RewriteRule that prepends the /products to %{REQUEST_URI}:

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{REQUEST_URI} ^/some-word/
     RewriteRule ^ /products%{REQUEST_URI} [R=301,L]
    </IfModule>
    

    Make sure to put this at the top of your .htaccess, otherwise it might not work because of the other rules.

    Login or Signup to reply.
  2. 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:

    Redirect 301 /some-word/ /products/some-word/
    

    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:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search