Welcome! Log In Create A New Profile


Error 404 when the URL contains special characters (braces, hyphens etc.)

July 31, 2013 05:44PM
In my (Zend Framework 2) application I have a catalog of cities with links to sports pages:

page "Cities" (/catalog)
Madrid link: website.tld/catalog/Madrid
Berlin link: website.tld/catalog/Berlin
London link: website.tld/catalog/London

page "Sports in London" (/catalog/London)
Foo link: website.tld/catalog/London/Foo
Bar (Bar) link: website.tld/catalog/London/Bar (Bar)
Baz - Baz link: website.tld/catalog/London/Baz - Baz

The URLs are escaped and work well. But when I try to reach a page with an unescaped special character like a brace (e.g. "website.tld/catalog/Berlin/Jeu de Paume (Real Tennis)" instead of "website.tld/catalog/Berlin/Jeu%20de%20Paume%20%28Real%20Tennis%29"), I get a 404 Error.

How to fix it?

What I want to achieve is a behaviour like à la Wikipedia -- You can use "http://en.wikipedia.org/wiki/Signal_(electrical_engineering)" or "http://en.wikipedia.org/wiki/Signal_%28electrical_engineering%29" and will always get the corect page.

Additional info:

System properties:

Debian 7, nginx 1.2.1, PHP 5.5.


user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
worker_connections 768;

http {

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

gzip on;
gzip_disable "msie6";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;


server {
listen 80;

if ($host ~ ^(?<project>.+)\.(?<area>.+)\.loc$) {
#set $project $1; # already set
#set $area $2; # already set

set $folder "$area/$project";
#set $domain "$project.$area.loc"; # equal to $host

access_log /var/log/nginx/$area/$project.access.log;
error_log /var/log/nginx/error.log;

gzip on;
gzip_min_length 1000;
gzip_types text/plain text/xml application/xml;

client_max_body_size 25m;

root /var/www/$folder/public/;

try_files $uri $uri/ /index.php?$args;
index index.html index.php;

location / {
index index.html index.php;
sendfile off;

location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {
deny all;

location ~ \.htaccess {
deny all;

if (!-e $request_filename) {
rewrite ^.*$ /index.php last;

location ~ \.php$ {
fastcgi_cache off;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_read_timeout 6000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV development;
fastcgi_param HTTPS $https;
Subject Author Posted

Error 404 when the URL contains special characters (braces, hyphens etc.)

automatix July 31, 2013 05:44PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 81
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 214 on March 20, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready