Forum Moderators: phranque
www-site-com/widget/ to www-site-com/cgi-bin/product?name=widget
with this in my httpd.conf:
RewriteCond %{REQUEST_URI}!stats
RewriteCond %{REQUEST_URI}!banners
RewriteRule ^([^./]+)/?$ /cgi-bin/product?name=$1 [L]
the problem is now that both:
www-site-com/widget
www-site-com/widget/
work (which is ok), but they should both go to:
www-site-com/widget/
as an extra I would also want to have a picture gallery of a product rewrite like this:
www-site-com/widget/pictures/
(and again that both /pictures and /pictures/ work but both go to /pictures/)
ofcourse the "pictures" is optional.
I thought of something like this:
RewriteRule ^([^./]+)/?([^./]+)?/?$ /cgi-bin/product?name=$1&page=$2 [L]
but I thought to show it here first to avoid breaking my site
Tristan
RewriteCond %{REQUEST_URI} !(\.¦/$)
RewriteRule . http://www.example.com%{REQUEST_URI}/ [R=301,L]
Rule: If there is a single char. (or more) requested, check the condition.
Cond: If the requested URI does not contain a (dot) or end in a / continue the rule.
Rule: If the Cond. was met, redirect the request to the original location 'with a slash'.
Justin
thanks! I've changed my httpd.conf for this domain to this:
----
RewriteCond %{REQUEST_URI}!(\.¦/$)
RewriteRule . %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_URI}!^stats$
RewriteRule ^([^./]+)/([^./]+)/$ /cgi-bin/product?name=$1&page=$2 [L]
RewriteCond %{REQUEST_URI}!^stats$
RewriteRule ^([^./]+)/?$ /cgi-bin/product?name=$1&page=main [L]
----
which adds the end-/ to pages ( www-site-com/widget/ ) and allows for a product "mainpage" and detail pages
This seems to work all okay.
these are the rewrites I currently use:
----
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(s?html?¦php)\ HTTP/
RewriteRule ^(.*)index\.(s?html?¦php) [www-site-com...] [R=301,L]
RewriteCond %{REQUEST_URI}!(\.¦/$)
RewriteRule . %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_URI}!stats
RewriteRule ^([^./]+)/$ /cgi-bin/product?name=$1&page=main [L]
RewriteCond %{REQUEST_URI}!stats
RewriteRule ^([^./]+)/([^./]+)/$ /cgi-bin/product?name=$1&page=$2 [L]
----
so www-site-com/widget/ should load the underlying script with the "widget" product and "main" page; while for example www-site-com/widget/detail/ should load the underlying script with the "widget" product and "detail" page
Can anyone spot an error in the rewriteconditions or the order of them?
Thanks!
I would suggest using a server headers checker to determine if you script is generating an external redirect response, which would cause the client to make a second request using the URL provided in that redirect response.
I use the "Live HTTP Headers" extension to the Firefox browser for this kind of testing -- very handy.
Jim