如何301在.htaccess中将旧的动态URL重定向到与其相关的新动态URL


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

旧URL结构:http://www.statebankofindiaifsccode.com/state-bank-of-india-sbi-ifsc-code/assam

在上面这个文件夹后的url/印度国家银行sbi ifsc代码/

值是动态的,就像它们是动态生成的状态一样。

新的Url结构:http://www.statebankofindiaifsccode.com/state-bank-of-india/assam

对于上面所有具有不同状态的动态url,我希望它们重定向到如上所示的新url结构。

我当前的htaccess代码:

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

请帮助我,我尝试了许多组合使用,重定向301,重定向匹配等

但没有什么对我有用。我检查了其他相关的问题,但没有发现类似的模式重定向。

请建议301重定向只使用.htaccess,因为它将对SEO有用。

用以下规则替换您的规则:

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]