[英]Redirect php file to homepage nginx
我正在尝试使用old.php
将old.php
(包括任何参数)重定向到主页,应该是301 redirect
我尝试了以下重写(在服务器块中),但不起作用
rewrite ^old.php(.*)$ https://www.example.com permanent;
我也有一个PHP位置块
location ~* \.php$ {
root /var/www/example.com/public_html/www;
try_files $uri =404;
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
您的rewrite
指令不起作用,因为URI以/
开头。 尝试更换:
rewrite ^old.php(.*)$ https://www.example.com permanent;
有:
rewrite ^/old.php(.*)$ https://www.example.com permanent;
一种解决方案,其中有不止一种,是将原始的old.php文件替换为...。
<?php
header("HTTP/1.1 301 Moved Permanently");
if( $_SERVER['QUERY_STRING'] == "" ) { $qs=""; } else { $qs = "?" . $_SERVER['QUERY_STRING']; }
header("Location: https://www.example.com" . $qs)
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.