Abilash Erikson
Abilash Erikson

Reputation: 351

URL Redirection by removing a string

I have to redirect some url .

for example if the url is

www.example.com/shop   valid

www.example.com/shop/red-product  need redirection to www.example.com/red-product

www.example.com/shop/green  need redirection to www.example.com/green

www.example.com/shop/any-string  need redirection to www.example.com/any-string

How i can do this . Please help .

My current htacess file is

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

Redirect 301 /bio/ https://www.example.com/bio/

Options -Indexes

Upvotes: 0

Views: 24

Answers (2)

anubhava
anubhava

Reputation: 785058

You may replace your code with this one:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule ^shop/(.+)$ /$1 [L,NC,NE,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

Upvotes: 1

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Below rule should work we are matching the group after shop only.

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/shop/(.*)
RewriteRule ^ http://www.example.com/%1 [R]

Upvotes: 1

Related Questions