Saturday 15 February 2014

nginx - How to replace special character in HTTP request URI? -


On a Zend Framework 2 website (Test Environment on NGNX and Live Environment on Apache) A category "Course" and its pages In this way URIs are:

  domain.tld / courses / 123- Definitely the name, which may contain ®, â, ¬, (,), and other special characters   

The curriculum has come from the database and is URL-encoded for internal links:

  domain.tld / courses / 123-name% 20of% 20course% 20that % 20 Can% 20P TiT% 20% C2% AE% 2C% 20% E2% 82% AC% 2C% 20% C3% A4% 2C% 20% (% 2C% 20)% 2C% 20% and% 20 other% 20 special% 20chars   

This is working fine, but when I try to use a page using a special character without encoding a 404-error .

An example of a website that uses special characters Wikipedia. You can use

  http://en.wikipedia.org/wiki/Signal_ (Electrical_Engineering)   

or

  Http://en.wikipedia.org/wiki/Signal_%28electrical_engineering%29   

and always get the pages you want.

Does anybody know how to achieve such behavior ("a la Wikipedia")? (Possibly due to the .htaccess rule can HTTP redirect?)


update:

/ etc / nginx / axle -common-vhost

  server {80 says; Server_name foo.loc bar.loc baz.loc; If ($ host ~ ^ (?? Project & gt; +) \. (? & Lt; Area & gt ;.) Loc Loc $) {Set $ ​​folder "$ area / $ project"; } Access_log /var/log/nginx/$area/$project.access.log; Error_log /var/log/nginx/error.log; Jeez; 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 index.php; Place / {index index index.php; Send file off; } Place ~ (\ .inc \ .php | \ .tpl | \ .qq | | .pl.php | \ dd) $ {reject all; } Location ~ \ .htaccess {reject all; } If (! -e $ request_filename) {rewrite ^. * $ / Endex.php; } 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; Includes fastcgi_params; Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; Fastcgi_param APPLICATION_ENV development; Fastcgi_param HTTPS $ https; }}    

By creating the correct rewrite rule inside you, retyping the desired URL to get the behavior Of your .htaccess file

I suggest you have a look at, especially

No comments:

Post a Comment