You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Georg Markus Dittrich <go...@yahoo.de> on 2002/11/19 19:32:21 UTC

[users@httpd] mod_rewrite & query strings -> php variables, sessions

hello,

following problem - every help appreciated (Apache 1.3 newest version on redhat linux, rewriting urls on htaccess level):

to put it in a nutshell i would like to know, how i can include the query_string in rewrite rules not only on the output side, but on the incoming one (the URL, which has to be rewritten);

I use the following rule:

^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)\.html $1\.php?category=$2\&item=$3\&shop_lang=$4\&type=$5

to rewrite URL´s like http://www.maskworld.com.exxs.net/display-department_152_0_german_beard.html 

to an URL like http://www.maskworld.com.exxs.net/display-department.php?category=152&item=0&shop_lang=german&type=beard 

This way it appears that the page is made of static pages and search engines can spider them.

But still I want to use sessions without cookies in PHP and transfer variables with url-encode. That is why I would like to use the following rule, as PHP attaches it´s session variable and other data automatically after the xxx.html):

RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)\.html\??(.*) $1\.php?category=$2\&item=$3\&shop_lang=$4\&type=$5\&$6

but this does not work. I have found out that it has something to do with the ´?´ at the beginning that starts the query_string. As I am rewriting the URL myself I already have the ? in my new URL and therefore would like to paste all the stuff that comes in the original URL behind the last variable ($6).

But apparently mod_rewrite has a general problem with ? marks. I tried to escape it and use the second one as a {1,0} indicator as there might be a session_id or not. But it does not work either way.

By reviewing the logs I have found out, that no matter how I define the rule, when I call an URL like http://www.maskworld.com.exxs.net/display-department_152_0_german_beard.html?shit=5 the server initialises the rewrite process with the URL http://www.maskworld.com.exxs.net/display-department_152_0_german_beard.html, but without the remaining characters after the .html. So everything after the question mark is ignored? Why? Why is there nowhere documentation on this topic, or is there? How can I fix this? there has to be a way to work with the session variables; OT: could I get php to work with a different variable introductor? /OT Would this work with the rewrite then?

I have worked for a while now, but I am stuck - any help is greatly appreciated. 

thanx a lot in advance - gorg.



---------------------------------
Gesendet von http://mail.yahoo.de.
3,5% Zinsen ab dem 1. EUR. Das Tagesgeldkonto mit den besten ZinsenTäglich verfügbar.
 Kostenlose Kontoführung. Jetzt eröffnen! Extrakonto bei der DiBa.

Re: [users@httpd] mod_rewrite & query strings -> php variables, sessions

Posted by Joshua Slive <jo...@slive.ca>.
On Tue, 19 Nov 2002, Georg Markus Dittrich wrote:
> to put it in a nutshell i would like to know, how i can include the
> query_string in rewrite rules not only on the output side, but on the
> incoming one (the URL, which has to be rewritten);

> RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)\.html\??(.*)
> $1\.php?category=$2\&item=$3\&shop_lang=$4\&type=$5\&$6

This is actually much simpler than you might think.  If you tag the option
[QSA] ("Query String Append") on to the end of the RewriteRule,
mod_rewrite will automatically grab the query string from the request and
add it to the query string of the target.  So you probably just want
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)\.html $1\.php?category=$2\&item=$3\&shop_lang=$4\&type=$5\&$6 [QSA]

In general, you can't match the query string with a RewriteRule.  You need
to use a RewriteCond and match agains %{QUERY_STRING}.

Joshua.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org