如何使用 htaccess 将带有参数的旧 url 重定向到新的 seo url

how to redirect old url with parameters to new seo url using htaccess

想要将参数 url 重定向到 seo 友好的 url

https://example.com/a.php?slug=vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present

https://example.com/vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present

https://example.com/tag.php?id=Virtual-reality

https://example.com/tag/Virtual-reality

我当前的 .htaccess 代码

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)/?$ a.php?slug= [L]


RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]

这样说:

Options -MultiViews
RewriteEngine On    

RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]

# external redirect to redirect old URL to pretty URL    
RewriteCond %{THE_REQUEST} /a\.php\?slug=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteCond %{THE_REQUEST} /tag\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /tag/%1? [R=301,L,NE]

RewriteRule ^tag/([\w-]+)/?$ tag.php?id= [L,QSA,NC]

# internal rewrite to forward to actual URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ a.php?slug= [L,QSA]