Forum Moderators: phranque
Here´s the problem: I have two situations that I want to handle in different ways:
1) [thisvendor.mysite.com...]
-> [mysite.com...]
2) [thisvendor.mysite.com...]
-> [mysite.com...]
Here´s the rule I made:
RewriteEngine on
RewriteCond %{REQUEST_URI}!\.cgi
RewriteCond %{REQUEST_URI}!\.css
RewriteCond %{REQUEST_URI}!\.gif
RewriteCond %{REQUEST_URI}!\.jpg
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mysite\.com
RewriteRule ^([^/^\\]+)[/\/]([^/^\\]+) /home/mysite/www/cgi-bin/page.cgi?vendor=%1\§ion=$1\&$2 [L]
It works fine for the #2 case, that is, when all the parameters are found. But, for case #1, I end up with a lost "&" in the rewritten url.
I´ve read the mod_rewrite docs several times, but couldn´t figure out how to write different rules for different kinds of url.
Hope you guys can help me, I´ve spent several hours on this, without success...
Thanks a lot!
phoenix_fly
I did try to add this rule in the end, thinking that the urls that didn´t match the first pattern, would then match this one:
RewriteRule ^(.+) /home/mysite/www/cgi-bin/page.cgi?vendor=%1\§ion=$1 [L]
But then it does something unexpected: despite typing or not the "/products" or "/search/keyword=cases" or whatever, my page.cgi receives this as the 'section'value:
cgi-bin/page.cgi
I´m totally lost...
RewriteCond %{REQUEST_URI} !\.(cgi¦css¦gif¦jpg)$
Jim
Thanks a lot for the post.
So, would it be this code:
RewriteEngine on
RewriteCond %{REQUEST_URI}!\.(cgi¦css¦gif¦jpg)$
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mysite\.com
RewriteRule ^([^/^\\]+)[/\/]([^/^\\]+) /home/mysite/www/cgi-bin/page.cgi?vendor=%1\§ion=$1\&$2 [L]
RewriteCond %{REQUEST_URI}!\.(cgi¦css¦gif¦jpg)$
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mysite\.com
RewriteRule ^(.+) /home/mysite/www/cgi-bin/page.cgi?vendor=%1\§ion=$1 [L]
?
Seems strange to me, but as you said the rewritecond only affects the next (the first?) rewriterule after it, I came to this.
Thanks
André
The code above worked perfectly. By the way, there was a little typo in the first rule, so here´s the tested code:
RewriteEngine on
RewriteCond %{REQUEST_URI}!\.(cgi¦css¦gif¦jpg)$
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mysite\.com
RewriteRule ^([^/^\\]+)/(.+) /home/mysite/www/cgi-bin/page.cgi?vendor=%1\§ion=$1\&$2 [L]
RewriteCond %{REQUEST_URI}!\.(cgi¦css¦gif¦jpg)$
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mysite\.com
RewriteRule ^(.+) /home/mysite/www/cgi-bin/page.cgi?vendor=%1\§ion=$1 [L]
But, as I had the beast domesticated, I am trying to be able to use "?" in the first RewriteRule regexp, instead of "/"
current: ^([^/^\\]+)/(.+)
desired: ^([^/^\\]+)\?(.+)
The reason is that the "?" is the normal behaviour for the html when I put the "http://www.vendor.mysite.com/search" as the "action" attribute in the FORM tag.
But even with the backslash it doesn´t work, I don´t understand why. Is there a special way to escape the "?" in mod_rewrite? Maybe use the hex equivalent?
Thanks
André