Forum Moderators: phranque
RewriteEngine on
RewriteRule webscript/(.*)/(.*)/?$ /cgi-bin/webscript.pl?page=$1.html&cart_id=$2 [L]
My directory structure is:
- docs
- images
- cgi-bin
my .htaccess file resides under the cgi-bin directory and so does the script webscript.pl
now I get the desired effect
of dynamic urls going to
www.widget.com/cgi-bin/webscript.pl?&page=PAGENUMBER&cart_id=CARTNUMBER
when
www.widget.com/cgi-bin/webscript/PAGENUMBER/CARTNUMBER
is entered as the reference URL
What is messing me up is that all the images URL's which I don't want touch goes to
www.widget.com/cgi-bin/webscript/images/picture.jpg
instead of leaving the ./images/picture.jpg alone
I don't have a .htaccess file under my image directory, so shoun't my images being referenced be left alone.
Any ideas how to fix this?
That depends on the current RewriteOptions inherit setting.
Also, you've used the very-ambiguous ".*" pattern, which will match anything equal to or longer that that URL-path you expect. I'd suggest:
RewriteCond %{REQUEST_URI} !\.(gif¦jpe?g¦png)$
RewriteRule webscript/([^/]+)/([^/]+)/?$ /cgi-bin/webscript.pl?page=$1.html&cart_id=$2 [L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com]
Jim
To my web browser:
/images
/docs
/cgi-bin
are all at the same root level under my domain
however physically on the disk
its
/home/httpd/vhosts/domain-name/cgi-bin
/home/httpd/vhosts/domain-name/httpdocs/images
/home/htptd/vhosts/domain-name/httpdocs/docs
could this be messing things up?
The .htaccess code must be located in a directory in or above the directory containing the pages/images to be rewritten.
The RewriteRules in .htaccess will use the local URL-path, not the directory path, when deciding to rewrite or not.
So the .htaccess code location is filesystem dependent, while the code itself is URL-path dependent.
I hope that makes sense, that's the best I can explain it...
Jim
I moved the .htaccess file to my root webserver directory (www.domain.com) which resides under /home/vhosts/httpd/domainname.com/httpdocs
and use the following code in my .htaccess file
RewriteCond %{REQUEST_URI}!\.(gif¦jpe?g¦png)$
RewriteRule ([^/]+)/([^/]+)/?$ /cgi-bin/webscript.pl/page=$1.html&cart_id=$2 [L]
and simplified my static request string to:
www.domain.com/PAGE/CART
and everything works.
When they say mod_rewrite is a difficult to learn as sendmail, they were wrong. mod_rewrite is like sendmail on drugs. At least with sendmail, you don't have to worry about its location.
And those d*mm unix/linux control panels, add more twists and turns with their own .htaccess files and htpd.conf variations, its enough to drive you insane.
After all this work, google better start deep crawling my site :)
Thanks JD for your input