簡體   English   中英

如何使用 htaccess 將帶有參數的舊 url 重定向到新的 seo url

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM