skip to Main Content

I want to redirect url using htaccess file from project root folder.

I can easily redirect url like www.xyz.com/ar/contact to www.xyz.com/contact using this

Redirect 301 /ar/contact/ /contact/

but how to redirect url like this

www.xyz.com/ar/shop/xyz.html to www.xyz.com/shop/xyz.html

I have tried this

Redirect 301 /ar/shop/^(.*)$ /shop/$1

Redirect /ar/shop/^(.*)$ /shop/$1 [R=301,L]

Redirect ^/ar/shop/(.*) /shop/$1

but it did’t work.

2

Answers


  1. Could you please try following. Written and tested with shown samples only.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/ar/(.*)/? [NC]
    RewriteRule ^(.*) /%1 [R=301,NE,L]
    
    Login or Signup to reply.
  2. You can not use a regex based pattern in Redirect directive. If you want to redirect everything that comes after /ar/shop/ to /shop/ then just use a static pattern /ar/shop/ .

    Redirect 301 /ar/shop/ /shop/
    

    This will redirect all URIs starting with /ar/shop/ to /shop/ . forexample /ar/shop/foobar will get redirected to /shop/foobar > .

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