我在使用 WordPress 時遇到了重定向問題,并從 URL 中洗掉了日期:
老的:
https://www.example.de/2022/03/03/here-is-the-article-name-2582/
新的:
https://www.example.de/here-is-the-article-name-2582/
重定向錯誤:
https://www.example.de/03/
他一直在“白天”路徑上重定向。
這是我的.htaccess測驗:
########### REDIRECT 301 ############
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9] )/([0-9] )/([0-9] )/(.*)$ /$3 [R=301,NC,L]
RewriteRule ^category(/.*|)$ /kategorie/$1 [R=301,L,NC]
RewriteRule ^tag(/.*|)$ /schlagwort/$1 [R=301,L,NC]
#RedirectMatch 301 /([0-9] )/([0-9] )/([0-9] )/(.*)$ /$4
########### ALTE URL mit DATUM - REDIRECT 301 - OHNE Datum ############
#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteBase /
# RewriteRule ^([0-9] )/([0-9] )/([0-9] )/(.*)$ /$3 [R=301,NC,L]
#</IfModule>
我可以為正確的路由做些什么?
uj5u.com熱心網友回復:
這個重定向 301 現在對我有用:
########### REDIRECT 301 ############
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9] )/([0-9] )/([0-9] )/(.*)$ /$4 [R=301,NC,L]
RewriteRule ^category(/.*|)$ /kategorie/$1 [R=301,L,NC]
RewriteRule ^tag(/.*|)$ /schlagwort/$1 [R=301,L,NC]
uj5u.com熱心網友回復:
我看到您發現了問題并更改了規則以使用第四個捕獲組而不是第三個。
還有另一種解決方案。您可以通過洗掉不需要的括號從規則中洗掉未使用的捕獲組。然后您可以使用第一個(也是唯一的)捕獲組。
RewriteRule ^[0-9] /[0-9] /[0-9] /(.*)$ /$1 [R=301,NC,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/440153.html
