Abhishek Singh
Abhishek Singh

Reputation: 77

how to remove file name and folder name from the url by htaccess

I have used code that area give below

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^blog/(.*)$ /$1 [L,NC,R]

but by using these code I can only remove only one page name . can you guys please help me with this.

In other words, I want to change the URL from:

www.xyz.com/blog/post1/post3
www.xyz.com/blog/post2/post4

To:

   www.xyz.com/post3  
   www.xyz.com/post4

Upvotes: 2

Views: 71

Answers (1)

anubhava
anubhava

Reputation: 784888

You can use:

RewriteRule ^blog/(?:.*/)?([^/]+)/?$ /$1 [L,NC,NE,R=301]

This will redirect /blog/post1/post3 to /post3 and /blog/post2 to /post2.

Upvotes: 1

Related Questions