[英]How to rewrite wordpress urls with index.php in them
I want to make custom WordPress URLs like this : http://example.com/index.php?productID=123
and for categories http://example.com/index.php?categoryID=123
and the reason is we have a website written in some old custom CMS and we want to move it to WordPress and we don't want to lose our indexes in google, The problem here is whenever we include index.php
in custom URL rewrite it doesn't work and it automatically removes the index.php
我想制作如下这样的自定义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
here are the codes i tried: 这是我尝试的代码:
add_rewrite_rule('index.php?p=(.*)', 'index.php?productId=$matches[1]', 'top');
add_rewrite_rule('index.php?cat=(.*)', 'index.php?categoryId=$matches[1]', 'top');
I also tried this plugin , it works fine but the problem is it converts the ?
我也试过这个插件 ,它工作正常,但问题是它转换了?
into %3F
in URLs which causes 404 error 进入URL中的%3F
,导致404错误
You should use 301 redirects in the .htaccess
file, as per Google' suggestion. 根据Google的建议,您应该在.htaccess
文件中使用301重定向。 https://support.google.com/webmasters/answer/93633?hl=en https://support.google.com/webmasters/answer/93633?hl=zh_CN
An example of a line you'd add to your .htaccess
would be: redirect 301 /index.php?oldProduct=123 /index.php?newProduct=123
您要添加到.htaccess
中的一行示例如下: redirect 301 /index.php?oldProduct=123 /index.php?newProduct=123
But you really have limitless options. 但是您确实有无限的选择。 You can see more examples at http://www.isitebuild.com/301-redirect.htm 您可以在http://www.isitebuild.com/301-redirect.htm上看到更多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.