Welcome! Log In Create A New Profile

Advanced

Нужно добавить параметр к url

Posted by Akuma 
Нужно добавить параметр к url
December 08, 2010 10:17AM
Здравствуйте!

Мне нужно дописывать параметр ко всем url, которые будут обрабатываться с помощью php с точкой входа index.php.
То есть из запроса site.ru/text/first нужно получить что-то типа site.ru/index.php?s=1&q=/text/first
Проблема в том, что этот параметр (s=1) нужно дописывать и к самому индексу! То есть при обращении site.ru/ нужно передавать запрос на index.php?s=1

Текущая конфигурация:

[code]
server {
listen 80;
server_name_in_redirect off; # ХЗ
server_name site.ru www.site.ru;

set $s 1;
set $sroot /var/www/eden/data/www/site.ru;

root /var/www/eden/data/www/site.ru;
error_page 404 /404.html;
error_log /var/www/httpd-logs/site.ru.error.log notice;
access_log /var/www/httpd-logs/site.ru.access.log;
client_body_in_file_only off;

include nginx.conf.site;
}
[/code]

nginx.conf.site;

[code]
location / { root $sroot; index index.php; try_files $uri @eden; }
location ~* /modules/ { internal; }
location ~* inc/ { internal; }
location ~* \.inc$ { internal; }
location ~* /\.ht { internal; }

location = /favicon.ico { try_files /404.html break; }
location = /style.css { try_files /shared/css/$s.css /404.html break; }
location = /robots.txt { try_files /shared/robots/$s.txt /404.html break; }
location = /shared/dot.gif { try_files /shared/dot.gif /404.html; break; }
location ~* ^/content/images/([^\/]+)$ { try_files /shared/images/$s/$1 /404.html; break; }
location ~* ^/files/([^\/]+)$ { try_files /shared/files/$s/$1 /404.html; break; }
location ~* /admin/ {
root $sroot;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
break;

# мб будут косяки... посмотреть
}
location ~ \.php$ {
root $sroot;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING s=$s&q=$uri&$args;

break;
}
location @eden {
root $sroot;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING s=$s&q=$uri&$args;

break;
}
[/code]

Такая конфигурация работает частично (!), но с ненужным переписыванием ВСЕХ запросов - если обращение идет к css, оно тоже переписывается, а это мне не нужно
[code]
location = / { root $sroot; index index.php; }
location / { root $sroot; index index.php;
if (!-f $request_filename) { rewrite ^(.*)$ /index.php?s$s&q=$1 last; break; }
if (!-d $request_filename) { rewrite ^(.*)$ /index.php?s=$s&q=$1 last; break; }
}
location ~* /modules/ { internal; }
location ~* inc/ { internal; }
location ~* \.inc$ { internal; }
location ~* /\.ht { internal; }

location = /style.css { try_files /shared/css/$s.css /404.html break; }
location = /robots.txt { try_files /shared/robots/$s.txt /404.html break; }
location = /shared/dot.gif { try_files /shared/dot.gif /404.html; break; }
location ~* ^/content/images/([^\/]+)$ { try_files /shared/images/$s/$1 /404.html; break; }
location ~* ^/files/([^\/]+)$ { try_files /shared/files/$s/$1 /404.html; break; }
location ~* /admin/ {
root $sroot;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name?s=$s;
break;

# мб будут косяки... посмотреть
}
location ~ \.php$ {
root $sroot;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

break;
}
[/code]



Edited 1 time(s). Last edit at 12/08/2010 10:20AM by Akuma.
Re: Нужно добавить параметр к url
December 09, 2010 07:17AM
А вот так правильно работает обращение к index.php, но любой запрос вида site.ru/text/first выдает "No input file specified.".
Есть ли возможность проследить, КАК идет обработка запроса в nginx? То есть полностью, от запроса до проверок и реврайтов?
[code]
location / { root $sroot; index index.php; try_files $uri @eden; }
location ~* /modules/ { internal; }
location ~* inc/ { internal; }
location ~* \.inc$ { internal; }
location ~* /\.ht { internal; }

location = /favicon.ico { try_files /404.html break; }
location = /style.css { try_files /shared/css/$s.css /404.html break; }
location = /robots.txt { try_files /shared/robots/$s.txt /404.html break; }
location = /shared/dot.gif { try_files /shared/dot.gif /404.html; break; }
location ~* ^/content/images/([^\/]+)$ { try_files /shared/images/$s/$1 /404.html; break; }
location ~* ^/files/([^\/]+)$ { try_files /shared/files/$s/$1 /404.html; break; }
location ~* /admin/ {
root $sroot;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
break;

# мб будут косяки... посмотреть
}
location ~ \.php$ {
root $sroot;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING s=$s&q=$uri$args;

break;
}
location @eden {
root $sroot;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING s=$s&q=$uri$args;

break;
}
[/code]
Re: Нужно добавить параметр к url
December 09, 2010 08:22AM
Решение оказалось простым, как все гениальное: в блоке @eden нужно было написать fastcgi_param SCRIPT_FILENAME $document_root/index.php; , а не то, что там было раньше... Невнимательность -__-
Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 109
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready