将 php 文件重定向到主页 nginx
Redirect php file to homepage nginx
我正在尝试将 old.php
(包括任何参数)重定向到主页 nginx.It 应该是 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;
}
一种解决方案,而且还有不止一种,就是将原始 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)
?>
您的 rewrite
指令无效,因为 URI 以 /
开头。尝试替换:
rewrite ^old.php(.*)$ https://www.example.com permanent;
与:
rewrite ^/old.php(.*)$ https://www.example.com permanent;
我正在尝试将 old.php
(包括任何参数)重定向到主页 nginx.It 应该是 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;
}
一种解决方案,而且还有不止一种,就是将原始 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)
?>
您的 rewrite
指令无效,因为 URI 以 /
开头。尝试替换:
rewrite ^old.php(.*)$ https://www.example.com permanent;
与:
rewrite ^/old.php(.*)$ https://www.example.com permanent;