user3244348
user3244348

Reputation: 45

Nginx URL rewrite rules in my administration

How can I rewrite a URL after logging in to the back end? I need to change the following from www.domain.com/administration/index.php, www.domain.com/administration/nextpage.php to www.domain.com/administration/index, www.domain.com/administration/nextpage This is my actual configuration:

server {
    server_name domain.com;
    return 301 $scheme://www.domain.com$request_uri;
}

server {
        listen 80;
        root /usr/share/nginx/www;
        index index.php;
        server_name www.domain.com;



   location / {
        rewrite ^([^\.]*)$ /$1.php;
    }

    location = / {
        rewrite ^ /index.php;
    }


    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
      }
}

Upvotes: 2

Views: 63

Answers (2)

Antoine Wils
Antoine Wils

Reputation: 349

location /administration { 
    rewrite ^([^\.]*)(\.php)?$ /$1; 
}

Adding that block to your configuration will remove the .php from requests to /administration

Upvotes: 1

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42899

This will try adding an extension PHP when the actual URI fails

location /administration {
  try_files $uri $uri/ /$uri.php$is_args$query_string;
}

Upvotes: 1

Related Questions