Skip to main content

Pretty URL on Nginx server

If you’re using Apache webserver, you don’t need to do some server configuration since Apache webserver is using .htaccess for URL rewrite, and .htaccess file is already included.

For Nginx users, you need to modify your Nginx configuration to be able to use Pretty URL feature.

Nginx config located at “/etc/nginx” folder or “/etc/nginx/sites-enabled/default.conf”. Nginx configuration file have “.conf” file format.

Here is the code for Pretty URL:

location / {
	try_files $uri $uri/ @rewrite_url;
}

location @rewrite_url {
	rewrite ^/(.*)$ /index.php?viewpage=$1 last;
}

If you’re not familiar with Nginx configuration, you must put code above inside “server” section.

Full code sample on Laragon webserver:

server {
	listen 8080 default_server;
	server_name localhost ;
	root "C:/laragon/www/";
	
	index index.html index.htm index.php;
 
	# Access Restrictions
	allow       127.0.0.1;
	deny        all;
 
	include "C:/laragon/etc/nginx/alias/*.conf";

	location / {
		try_files $uri $uri/ @rewrite_url;
	}

	location @rewrite_url {
		rewrite ^/(.*)$ /index.php?viewpage=$1 last;
	}
	
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass php_upstream;		
		#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

	charset utf-8;
	
	location = /favicon.ico { access_log off; log_not_found off; }
	location = /robots.txt  { access_log off; log_not_found off; }
	location ~ /\.ht {
		deny all;
	}
	
}

After Nginx config already updated, restart your Nginx server to apply changes, then you can activate “Pretty URL” from Admin settings.

Note: To make it work, make sure you’re using the latest version of CloudArcade, current version is v1.2.7 when this post was written.