: Redirect http to https with nginx and rewrite a rule gives redirect loop I want to redirect http to https along with rewrite ^(.*)$ /.php; My nginx virtualhost file: server { listen
I want to redirect http to https along with
rewrite ^(.*)$ /.php;
My nginx virtualhost file:
server {
listen 80;
server_name domain.com;
return 301 $server_name$request_uri; }
server {
listen 443 ssl;
server_name domain.com;
root /var/nginx/html;
ssl_certificate /home/domain.crt
ssl_certificate_key /home/domain.key
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /.php;
}
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm$
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
include fastcgi_params;
}
}
…but this gives me a redirect loop. Can somebody point me what am I doing wrong?
More posts by @Nimeshi995
1 Comments
Sorted by latest first Latest Oldest Best
if (!-e $request_filename){
rewrite ^(.*)$ /.php;
}
try_files $uri $uri/ /index.html;
What happens if /.php does not exist either? I'm no expert on Nginx unfortunately, but on Apache this sort of rewrite could result in a rewrite loop (you would need to check that the file exists first before rewriting to it).
Should this not be rewritten using try_files only...? For example:
try_files $uri $url.php $uri/ /index.html;
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.