Reputation: 101
Old urls structure: http://www.statebankofindiaifsccode.com/state-bank-of-india-sbi-ifsc-code/assam
in above url after this folder /state-bank-of-india-sbi-ifsc-code/
values are dynamic, like they are states generated dynamically.
New Urls Structure : http://www.statebankofindiaifsccode.com/state-bank-of-india/assam
For all dynamic urls above with different states i want them to redirect to new url structure like shown above.
My current htaccess code:
RewriteRule ^([a-zA-Z0-9_-]+)-sbi-ifsc-code/([a-zA-Z0-9_-]+)$ /bankdetails-state.php?bankfromhtac=$1&statefromhtac=$2
RewriteRule ^([a-zA-Z0-9_-]+)-sbi-ifsc-code/([a-zA-Z0-9_-]+)/$ /bankdetails-state.php?bankfromhtac=$1&statefromhtac=$2
Please help me i tried many combinations using, Redirect 301, RedirectMatch etc.
But nothing works for me. I checked other related questions but don't find similar pattern redirects.
Please suggest 301 redirect using .htaccess only, since it will be useful for SEO.
Upvotes: 0
Views: 171
Reputation: 784958
Replace your rules with these rules:
RewriteEngine On
# old URL to new URL redirect
RewriteRule ^([\w-]+)-sbi-ifsc-code/([\w-]+)/?$ /$1/$2 [L,NC,NE,R=302]
# internal handler for new URI scheme
RewriteRule ^(state-bank-of-india)/([\w-]+)/?$ bankdetails-state.php?bankfromhtac=$1&statefromhtac=$2 [L,QSA,NC]
Upvotes: 1