Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用index.php重写wordpress URL_Php_Wordpress_Mod Rewrite_Url Rewriting - Fatal编程技术网

如何使用index.php重写wordpress URL

如何使用index.php重写wordpress URL,php,wordpress,mod-rewrite,url-rewriting,Php,Wordpress,Mod Rewrite,Url Rewriting,我想自定义WordPress URL,如下所示:http://example.com/index.php?productID=123和类别http://example.com/index.php?categoryID=123原因是我们有一个用一些旧的定制CMS编写的网站,我们想把它移到WordPress上,我们不想失去谷歌的索引,这里的问题是,每当我们在自定义URL重写中包含index.php时,它都不起作用,并且会自动删除index.php 以下是我尝试过的代码: add_rewrite_ru

我想自定义WordPress URL,如下所示:
http://example.com/index.php?productID=123
和类别
http://example.com/index.php?categoryID=123
原因是我们有一个用一些旧的定制CMS编写的网站,我们想把它移到WordPress上,我们不想失去谷歌的索引,这里的问题是,每当我们在自定义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错误根据谷歌的建议,您应该在
.htaccess
文件中使用301重定向

您要添加到
.htaccess
中的一行示例如下:
重定向301/index.php?oldProduct=123/index.php?newProduct=123


但你真的有无限的选择。您可以在

上看到更多示例。根据谷歌的建议,您应该在
.htaccess
文件中使用301重定向

您要添加到
.htaccess
中的一行示例如下:
重定向301/index.php?oldProduct=123/index.php?newProduct=123


但你真的有无限的选择。您可以在

中看到更多的示例,我认为您的值混淆了,regex应该是第一个参数和要匹配的uri模式,第二个是要解析的uri。但是除非您使用漂亮的URL,否则不会调用重写api。。在404启动并包含文件之前,您可以使用一个钩子(可能是init)来解析url。但是从长远来看,使用漂亮的URL会更好。我认为您的值混淆了,正则表达式应该是第一个参数和要匹配的uri模式,第二个是要解析的uri。但是除非您使用漂亮的URL,否则不会调用重写api。。在404启动并包含文件之前,您可以使用一个钩子(可能是init)来解析url。但从长远来看,最好使用漂亮的URL