Redirect NGINXhttps://www.example.com/index.php 到https://www.example.com/ 如何重定向?
我有一个问题,我认为我已经解决了,但我一直无法解决它。我想重定向:Redirect NGINXhttps://www.example.com/index.php 到https://www.example.com/ 如何重定向?,redirect,ssl,nginx,Redirect,Ssl,Nginx,我有一个问题,我认为我已经解决了,但我一直无法解决它。我想重定向: ---------------------------------------------------------------------------- | FROM | TO | --------------------------------------------------------------
----------------------------------------------------------------------------
| FROM | TO |
----------------------------------------------------------------------------
| https://www.wknet.se/index.php | https://www.wknet.se/ |
----------------------------------------------------------------------------
我试图补充:
location = /index.php {
return 301 https://www.wknet.se;
}
但是,在浏览器中,它变成了一个重定向错误,并有一个无休止的循环。这是我的配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name wknet.se www.wknet.se;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://www.wknet.se$request_uri;
}
server {
listen 443 ssl;
server_name wknet.se;
ssl_certificate /etc/nginx/ssl/SSL.crt;
ssl_certificate_key /etc/nginx/ssl/KEY.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
ssl_prefer_server_ciphers on;
return 301 https://www.wknet.se$request_uri;
}
server {
listen 443 ssl;
server_name www.wknet.se;
root /var/www/wknet.se/html;
index index.php index.html index.htm;
ssl_certificate /etc/nginx/ssl/SSL.crt;
ssl_certificate_key /etc/nginx/ssl/KEY.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
ssl_prefer_server_ciphers on;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ =404;
}
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location = /index {
return 301 https://www.wknet.se;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
error_log off;
log_not_found off;
}
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
log_not_found off;
expires 365d;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|png|gif|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~* \.(7z|ai|class|css|csv|ejs|eps|flv|html?|jar|jpe?g|js|json|lzh|m4a|m4v|mov|mp3|pdf|pict|pls|ps|psd|swf|tiff?|txt|webp)$ {
access_log off;
log_not_found off;
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
}
我在谷歌上搜索并测试了在互联网上找到的一些代码,但没有任何帮助。我遗漏了什么?您最好的选择是删除实际应用程序中指向
index.php
的所有链接,只服务任何特定请求,包括index.php
,而不尝试更改这些请求
一旦您在应用程序中处理,应该很少甚至没有链接,因为搜索引擎将在没有index.php
的情况下保存链接
不知道你现在在哪里
location = /index {
return 301 https://www.wknet.se;
}
。。。它存在于问题的解决方案中(当然与index.php问题无关),除非您特别想重定向index
文件夹,否则它可能会被删除,从而导致您出现问题
**编辑**
又刺了一刀。未测试,但可能会断开回路。
尝试在error_page 500 502 503 504/50x.html下方添加此内容代码>在原始配置中
# We need to check if the user has specifically requested "index.php"
# and only redirect if they have ($request_uri variable).
# Internal redirects ($uri variable) should be left alone to avoid a redirect loop.
if ( $request_uri ~ ^(/index\.php)$ ) {
return 301 https://www.wknet.se;
}
它不起作用,我补充了建议,但我不断得到一个无休止的重定向循环错误。看看-->。我就是搞不懂。我怎么做嵌套的?对不起。。。这将始终导致重定向循环。我将修改答案。关于如何摆脱无休止的循环,没有其他解决方案吗(@damircalusic请参阅编辑部分I测试以添加编辑,但我得到了-->未知指令“if($request\u uri)”:/