![](/img/trans.png)
[英]How to 301 redirect in htaccess from old url with parameters to new?
[英]how to redirect old url with parameters to new seo url using htaccess
想要將 param 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=$1 [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=$1 [L,QSA,NC]
# internal rewrite to forward to actual URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ a.php?slug=$1 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.