Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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
Php Nginx-Wordpress重定向到默认url_Php_Wordpress_.htaccess_Redirect_Nginx - Fatal编程技术网

Php Nginx-Wordpress重定向到默认url

Php Nginx-Wordpress重定向到默认url,php,wordpress,.htaccess,redirect,nginx,Php,Wordpress,.htaccess,Redirect,Nginx,我有一个关于重定向的问题,我想重定向到example.com/12321.html到example.com?p=12321 在url类型之前我是用户,在这之后我将我的系统更改为seo url,并将内容名称更改为url。现在我要将来宾最好的系统重定向到?p= 我所尝试的 首先,我尝试在.htaccess上更改它,但我使用的是此代码 RewriteEngine On RewriteRule "^([0-9]+)+[^.html]" "https://www.example.com?p=$1" 我

我有一个关于重定向的问题,我想重定向到example.com/12321.html到example.com?p=12321

在url类型之前我是用户,在这之后我将我的系统更改为seo url,并将内容名称更改为url。现在我要将来宾最好的系统重定向到?p=

我所尝试的 首先,我尝试在.htaccess上更改它,但我使用的是此代码

RewriteEngine On
RewriteRule "^([0-9]+)+[^.html]" "https://www.example.com?p=$1" 
我想用nginx在nginx服务器块上编写这段代码

rewrite ^([0-9]+)+[^.html] https://www.example.com/$1 redirect;

我不明白这就是为什么不工作,我已经在那里工作了

好的,作为一个快速检查,您可以在Apache上尝试如下正则表达式:

RewriteRule ^/([0-9]+)\.html$ https://www.example.com?p=$1 [L,R=301]
对于Nginx,类似这样的内容:

rewrite ^/([0-9]+)\.html$ https://www.example.com?p=$1 permanent;
这应该匹配由数字
0-9
.html
组成的任何页面


您发布的规则与
.html
部分不匹配,这可能是它不起作用的原因。

不太清楚您想做什么,但是,除非您有一个
重写
规则,该规则将从
$uri
中删除
/
,首先,您的
重写^([0-9]+)+[^.html]规则 https://www.example.com/1美元
永远不会匹配,因为
$uri
不可能不以
/
开头,因此,
^([0-9]+)
永远不会捕获任何内容。(另外,
[^.html]
看起来也很可疑——我有一种感觉,它不会做你所期望的事情。)

正确的方法可能是:

rewrite ^/([0-9]+)\.html$ /?p=$1 redirect;

但是,根据和相关的,以下“循环”可能是您实际想要的:

if ($request_uri ~ ^/?p=([0-9]+)) {
    return 302 /$1.html
}
rewrite ^/([0-9]+)\.html$ /?p=$1;

上面的代码将确保
/?p=
样式仅在nginx和后端内部使用,而在外部,所有内容都会重定向到
.html
-样式的页面并从中提供服务。

谢谢您的回答,但它不起作用。我现在检查它:(我的错,忘记了捕获组和前导斜杠。