You are here: Re: php and mod_rewrite? « PHP Programming Language « IT news, forums, messages
Re: php and mod_rewrite?

Posted by Justin Koivisto on 02/02/06 16:12

namemattersnot@msn.com wrote:
> ok. i give up. need help :)
>
> here's the rule:
>
> RewriteRule ^test/(.+)/(.*)$ /index.php$2
>
> if i request: http://localhost/test/keyword/?show=files it properly
> redirects me.
>
> NOW, if i change the rule to: RewriteRule ^test/(.+)/(.*)$
> /index.php$2&key=$1
> it stops working.
>
> i figured out that if i remove ? from $show=files and change the rule
> to redirect to /index.php?$2, then i can use &key=$1. but i want to
> figure out how to redirect the ?show=files request AND at the end add
> &key=$1

RewriteRule does not match against the query string in mod_rewrite. To
match against that you will need to use

RewriteCond %{QUERY_STRING} pattern

RewriteRule works against the REQUEST_URI..

Therefore, as per your examples above:

RewriteRule ^test/(.+)/(.*)$ /index.php$2&key=$1

Consider this URI:
/test/dir1/dir2/?var=val

The result would be:
/index.phpdir2/&dir1

If you want to keep the original query string with your request, add the
[QSA] flag at the end of the RewriteRule statement (Query String Append)..

Using this with the same URI above...
RewriteRule ^test/([^/]+)/([^/]+)$ index.php?$2&key=$1 [QSA]

/index.php?dir2&key=dir1&var=val

HTH

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация