[英]How to rewrite wordpress urls with index.php in them
我想制作如下這樣的自定義WordPress URL: http://example.com/index.php?productID=123
: http://example.com/index.php?productID=123
以及類別http://example.com/index.php?categoryID=123
,原因是我們有一個使用某些舊的自定義CMS編寫的網站,我們希望將其移至WordPress,並且我們不想丟失google中的索引,這里的問題是,每當我們在自定義URL中包含index.php
,它都將無法正常工作並自動運行刪除index.php
這是我嘗試的代碼:
add_rewrite_rule('index.php?p=(.*)', 'index.php?productId=$matches[1]', 'top');
add_rewrite_rule('index.php?cat=(.*)', 'index.php?categoryId=$matches[1]', 'top');
我也試過這個插件 ,它工作正常,但問題是它轉換了?
進入URL中的%3F
,導致404錯誤
根據Google的建議,您應該在.htaccess
文件中使用301重定向。 https://support.google.com/webmasters/answer/93633?hl=zh_CN
您要添加到.htaccess
中的一行示例如下: redirect 301 /index.php?oldProduct=123 /index.php?newProduct=123
但是您確實有無限的選擇。 您可以在http://www.isitebuild.com/301-redirect.htm上看到更多示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.