How to rewrite a folder name using .htaccess?

Find best Web Development tips and Tricks.
Post Reply
apurba_soft
Posts: 10
Joined: Thu Jun 23, 2016 10:08 am
Location: India
Contact:

How to rewrite a folder name using .htaccess?

Post by apurba_soft » Thu Jun 23, 2016 11:43 am

Hi, I'm not good in .htaccess.

I have some links which are indexed by google and I don't want to loose those, so I want to redirect those links to a new folder name using .htaccess

Old link: http://songsdl.co/songs/hindi-songs.html

I want: http://songsdl.co/dl/hindi-songs.html

Please advice me guys.

arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

Re: How to rewrite a folder name using .htaccess?

Post by arnlweb » Thu Jun 23, 2016 11:47 am

Ok, simply you can try this.

Code: Select all

RewriteEngine on
RewriteRule ^dl/(.*) songs/$1
mod_rewrite can only rewrite/redirect requested URIs.
So you would need to request /songs/… to get it rewritten to a corresponding /dl/

Alternate tips:

Code: Select all

RewriteCond %{THE_REQUEST} ^GET\ /songs/
RewriteRule ^songs/(.*) /dl/$1 [L,R=301]
Hope, It helps you.

Post Reply