Forum Moderators: phranque
I´m having some trouble on finding the exact call to mod_rewrite. Can you help me out?
I need to have all the urls that correspond to my vendors (wich will be subdomains, like www.vendorx.mysite.com), translated into a call to a cgi script, with the vendor name as a parameter.
Example:
www.vendorx.mysite.com -> www.mysite.com/cgi-bin/page.cgi?vendor=ven
+dorx
I´m trying this, without success, in my .htaccess:
RewriteEngine on
RewriteRule ^www\.([^.]+)\.mysite\.com www\.mysite\.com/cgi-
+bin/page\.cgi\?vendor=$1
I´ve tried also to specify the target as the absolute path from my host, instead of with the url:
RewriteRule ^www\.([^.]+)\.mysite\.com /home/mysite/cgi-bin/pa
+ge\.cgi\?vendor=$1
... but Apache still doesn´t make it up for me!
Any ideas?
Thanks a lot,
phoenix_fly
Thanks a lot for the fast reply. And for the forum! (I come from perlmonks, and I think here I will find all the answers to the off-topic stuff there).
I´m really null to Apache, can you please give me more details? In fact, the doc showed the example below, and I didn´t understand the first two instructions.
How would be the line where I get the %1 (wouldn´t be $1?) and build the rewrite rule?
Thanks a lot.
André
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
Assuming you want to rewrite requests for *all* resources (pages, images, etc.) to the script, it'd look something like this:
RewriteEngine on
RewriteCond %{REQUEST_URI} !/cgi-bin/page\.cgi
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule .* /cgi-bin/page.cgi?vendor=%1 [L]
See the documentation cited in our forum charter [webmasterworld.com] for more information.
Jim
Thanks! It worked just fine... untill I tried to catch the directory typed and have it sent as a second parameter, like:
www.vendorx.example.com/products
turns to
www.example.com/cgi-bin/page.cgi?vendor=vendorx§ion=products
I really read the documentation you mentioned but, as they said it would, this really looks like a beast to understand... couldn´t figure out what´s wrong below:
RewriteEngine on
RewriteCond %{REQUEST_URI}!/cgi-bin/page\.cgi
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule /?([a-z]+)$ /home/example/www/cgi-bin/page.cgi?vendor=%1\§ion=$1 [L]
This works perfect when I do type the directory, like:
www.vendorx.example.com/products
But when I do not, the regexp just catches "html", whether i insert the slash or not after .com/
I don´t know where it comes from... "html"
Sorry to come you again, Jim
André
I´ve finally got it working with this:
RewriteEngine on
RewriteCond %{REQUEST_URI}!/cgi-bin/page\.cgi
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule ^(.+) /home/example/www/cgi-bin/page.cgi?vendor=%1\§ion=$1 [L]
The point seems to be that the rule does not affect the entire url, but only the subdirectories path, if any. If none, apache puts in there "/index.html", so this is why I was getting an unexpected "html" in my last regexp comming out of nowhere.
Please correct me if I said something wrong. this mod_rewrite still seems black magic for me... (hey, the docs could be more friendly don´t you guys think?)
Cheers
phoenix_fly