...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*) ? [QSA,C,E=page:$1]
RewriteRule [^/]*/([^/]*) ? [QSA,C,E=var:$1]
...
вопрос по mod_rewrite
.htaccess
Код:
в скрипте будут доступны переменные page=p1 и var=p2
Теперь хочу, чтобы передавались еще и GET-переменные.
http://HOSTNAME/p1/p2?a=1&b=2
В скрипте query_string = "&a=1&b=2"
http://HOSTNAME/p1/p2?a=1&b=2
в скрипте query_string = "&&a=1&b=2"
Откуда берутся эти символы "&"?
В логе mod_rewrite:
Код:
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] add path info postfix: /usr/local/www/HOSTNAME/p1 -> /usr/local/www/HOSTNAME/p1/p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] strip per-dir prefix: /usr/local/www/HOSTNAME/p1/p2 -> p1/p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] applying pattern '([^/]*)' to uri 'p1/p2'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (4) [perdir /usr/local/www/HOSTNAME/] RewriteCond: input='/usr/local/www/HOSTNAME/p1' pattern='!-d' => matched
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (4) [perdir /usr/local/www/HOSTNAME/] RewriteCond: input='/usr/local/www/HOSTNAME/p1' pattern='!-f' => matched
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (2) [perdir /usr/local/www/HOSTNAME/] rewrite 'p1/p2' -> '?'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (5) setting env variable 'page' to 'p1'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) split uri=? -> uri=, args=&a=1&b=2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] add per-dir prefix: -> /usr/local/www/HOSTNAME/
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] add path info postfix: /usr/local/www/HOSTNAME/ -> /usr/local/www/HOSTNAME//p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] strip per-dir prefix: /usr/local/www/HOSTNAME//p2 -> /p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] applying pattern '[^/]*/([^/]*)' to uri '/p2'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (2) [perdir /usr/local/www/HOSTNAME/] rewrite '/p2' -> '?'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (5) setting env variable 'gpar0' to 'p2'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) split uri=? -> uri=, args=&&a=1&b=2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] strip per-dir prefix: /usr/local/www/HOSTNAME/p1/p2 -> p1/p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] applying pattern '([^/]*)' to uri 'p1/p2'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (4) [perdir /usr/local/www/HOSTNAME/] RewriteCond: input='/usr/local/www/HOSTNAME/p1' pattern='!-d' => matched
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (4) [perdir /usr/local/www/HOSTNAME/] RewriteCond: input='/usr/local/www/HOSTNAME/p1' pattern='!-f' => matched
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (2) [perdir /usr/local/www/HOSTNAME/] rewrite 'p1/p2' -> '?'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (5) setting env variable 'page' to 'p1'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) split uri=? -> uri=, args=&a=1&b=2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] add per-dir prefix: -> /usr/local/www/HOSTNAME/
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] add path info postfix: /usr/local/www/HOSTNAME/ -> /usr/local/www/HOSTNAME//p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] strip per-dir prefix: /usr/local/www/HOSTNAME//p2 -> /p2
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) [perdir /usr/local/www/HOSTNAME/] applying pattern '[^/]*/([^/]*)' to uri '/p2'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (2) [perdir /usr/local/www/HOSTNAME/] rewrite '/p2' -> '?'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (5) setting env variable 'gpar0' to 'p2'
xxx.xxx.xxx.xxx - - [21/ноя/2008:18:26:02 +0000] [HOSTNAME/sid#285c2678][rid#29aae050/initial] (3) split uri=? -> uri=, args=&&a=1&b=2
Код:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*) ? [QSA,C,E=page:$1]
RewriteRule [^/]*/([^/]*) ? [QSA,C,E=var:$1]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*) ? [QSA,C,E=page:$1]
RewriteRule [^/]*/([^/]*) ? [QSA,C,E=var:$1]
Код:
<?php
echo $_SERVER["QUERY_STRING"];
?>
echo $_SERVER["QUERY_STRING"];
?>
http://HOSTNAME/p1?a=1&b=2
В скрипте query_string = "&a=1&b=2"
http://hostname/p1/p2?a=1&b=2
в скрипте query_string = "&&a=1&b=2"
т.е. чем больше строку пропускаю через [COLOR=#000000][COLOR=#0000BB]RewriteRule, тем больше символов "&" появляется в QUERY_STRING
[/COLOR][/COLOR]