簡體   English   中英

301重定向,忽略URL參數

[英]301 redirect that ignores URL parameters

我想出了如何使用.htaccess將朋友的舊博客檔案重定向到他的新WordPress檔案,如下所示:

RewriteEngine On

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

#Redirect to WP archive
RedirectMatch 301 ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3

但是,如果某人嘗試使用參數m = 1( http://www.mydomain.com/2010_04_01_archive.html?m=1 )訪問舊檔案,則該檔案不會重定向! 我們要忽略所有可能的參數,並像上面一樣重定向到http://www.mydomain.com/2010/04/01/

嘗試過此方法,但不起作用:

RewriteEngine On

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3 [R] 

謝謝你的幫助! 阿曼達

試試這個代碼:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive\.html$ /$1/$2/$3? [L,R=301,NC]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

刪除第一個/和$。

RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html /$1/$2/$3 [R=301] 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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