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

**URL:** <https://www.ruby-forum.com/t/error-404-when-the-url-contains-special-characters-braces-hyphens-etc/236035>\
**Category:** NGINX\
**Created:** [July 31, 2013, 11:45pm UTC](https://www.ruby-forum.com/t/error-404-when-the-url-contains-special-characters-braces-hyphens-etc/236035 "2013-07-31T23:45:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [July 31, 2013, 11:45pm UTC](https://www.ruby-forum.com/t/error-404-when-the-url-contains-special-characters-braces-hyphens-etc/236035/1 "2013-07-31T23:45:11Z")

</div>

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  
“[Signal - Wikipedia](http://en.wikipedia.org/wiki/Signal_(electrical_engineering))” or  
“[Signal - Wikipedia](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.

nginx.conf:

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/_;  
}

ax-common-vhost:

server {  
listen 80;  
server\_name  
foo.loc  
bar.loc  
baz.loc  
;

```
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 127.0.0.1:9001;
  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;  
}  
}

Posted at Nginx Forum:

> **[Error 404 when the URL contains special characters (braces, hyphens etc.)](https://forum.nginx.org/read.php?2,241421,241421#msg-241421)**
>
> 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
