我想为我的虚拟服务器的特定configuration,但我有一个问题,解释,以Nginx的:)
它很简单。 如果URI看起来像
example.com/whatever_1/whatever_2/.../whatever_n
我想重写它
example.com/index.php?request=whatever_1/whatever_2/.../whatever_n
第二个是如果URI以/administration/
like开头
example.com/administration/whatever_1/.../whatever_n
我想把它改写成
example.com/administration/index.php?request=whatever_1/.../whatever_n
我正在修理周围,并试图:
server { # listen 80; server_name example.com; index index.html index.php; root /srv/example/; location ~ /administration/(.*)$ { if (!-e $request_filename) { rewrite ^/(.*)$ /administration/index.php?request=$1 last; } break; #tried with and without it } location / #tried with and without this location block { if (!-e $request_filename) { #rewrite ^/(.*)$ /index.php?/$1 last; rewrite ^/(.*)$ /index.php?request=$1 last; } } location ~ \.php$ #boilerplate { # Filter out arbitrary code execution fastcgi_index index.php; include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; } }
但是这不起作用。 我对Nginx相当新,所以任何帮助将不胜感激。
谢谢,一月
这是nginx,而不是apache。 你应该尽可能避免重写(而且通常是可能的)。
使用try_files
代替。 例如:
location /administration/ { try_files $uri $uri/ /administration/index.php?request=$request_uri; } location / { try_files $uri $uri/ /index.php?request=$request_uri; }