Reputation: 40
I'm having a slight issue with Nginx and I'd be grateful if somebody could help me figure out the reason why it's not working. What I'd like to do is have the website redirect to the index page when the requested URL is invalid, but when using the following code:
server {
listen 80;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name localhost;
error_page 404 /index.php;
error_page 500 502 503 504 /50x.php;
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
it's not working exactly the way I'd like it to. This code works, but the URL is still http://example.com/nonexistantpage
when showing the index page. What I'd like is for the site to redirect to the index page, making the URL http://example.com
Upvotes: 0
Views: 135
Reputation: 42799
ok that's easy try this
error_page 404 =301 /;
if it doesn't work then use the full path
error_page 404 =301 http://example.com;
Upvotes: 1