简体   繁体   中英

How to 301 Redirect old dynamic URLs to their relevant New dynamic URLs in .htaccess

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM