在基于 Zend Framework 2 的网站(nginx 上的测试环境和 Apache 上的实时环境)上,有一个类别“课程”,其页面具有如下 URI:
domain.tld/courses/123-Name of course that can contain ®, €, (, ), and other special chars
课程名称来自数据库,并针对内部链接进行了 URL 编码:
domain.tld/courses/123-Name%20of%20course%20that%20can%20contain%20%C2%AE%2C%20%E2%82%AC%2C%20%C3%A4%2C%20(%2C%20)%2C%20and%20other%20special%20chars
它工作正常,但是当我尝试使用不编码的特殊字符访问页面时,会发生 404 错误。
使用空格字符的网站示例是维基百科。您可以使用
http://en.wikipedia.org/wiki/Signal_(electrical_engineering)
或者
http://en.wikipedia.org/wiki/Signal_%28electrical_engineering%29
并且总是得到你想要的页面。
有人知道如何实现这种行为(“à la Wikipedia”)吗?(也许使用 HTTP 重定向.htaccess
规则?)
更新:
/etc/nginx/ax-common-vhost
server {
listen 80;
server_name
foo.loc
bar.loc
baz.loc
;
if ($host ~ ^(?<project>.+)\.(?<area>.+)\.loc$) {
set $folder "$area/$project";
}
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;
}
}