简体   繁体   中英

Force Nginx to redirect plain domain to index.php?

I am currently running an IPS Community Suite forum on an Nginx server using EasyEngine and I have been trying to find a way to redirect http://example.com/ to http://example.com/index.php (only when it's simply the domain). Here is my current Nginx config for the server:

server {
listen 80;
listen 443;
ssl on;
ssl_certificate /var/www/example.com/cert.pem;
ssl_certificate_key /var/www/example.com/key.key;

server_name example.com www.example.com;
access_log /var/log/nginx/example.com.access.log rt_cache;
error_log /var/log/nginx/example.com.error.log;


root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include common/wpfc.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/classicaddons.com/conf/nginx/*.conf;
}

Any help would be appreciate!

Try this :

if ($request_uri = "/") {
    return 301 "/index.php";
}

You can add this before including other files.

You can use an exact match location block. See this document for more.

location = / {
    return 301 /index.php;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM