Forum Moderators: phranque
The only problem with it is that I have to setup RewriteRule for every xx.html page that I want to rewrite. I would prefer to be able to take the xx value and make the RewriteRule add it as a query string, for example:
User goes to http*//www.mydomain.com/articles/category/3.html
Server serves up http*//www.mydomain.com/cgi-bin/articles/morearticles.cgi?category=3
This works fine with the following .htaccess
code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!s
RewriteRule ^3\.html ../../cgi-bin/articles/morearticles.cgi?category=3 [T=application/x-httpd-cgi,L]
Any idea how I can take the 3.html and send it to the query string. I want to have a lot of categories an would rather not write a rule for each category number.
p.s. There is a space between } and!, I just couldnt work out how to get it to appear in my post.
http*//www.mydomain.com/cgi-bin/articles/morearticles.cgi?category=3&page=2
My thought was to use a format something similar to this:
http*//www.mydomain.com/articles/category/3-2.html
I cannot however find a way to get both parts of the URL passed to the query string.
Here is the .htaccess rewrite rule that works when there is only one value in the query string:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-s
RewriteRule ^(.+)\.html ../../cgi-bin/articles/morearticles.cgi?category=$1 [T=application/x-httpd-cgi,L]
TIA
Note, there is a space in the condition after the }
Within an hour of posting this I get it to work :)
I got frustrated but here is the code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-s
RewriteRule ([0-9]+)-([0-9]+)\.html$ ../../cgi-bin/article/morearticles.cgi?category=$1&page=$2 [T=application/x-httpd-cgi,L]
RewriteRule ^(.+)\.html ../../cgi-bin/articles/morearticles.cgi?category=$1 [T=application/x-httpd-cgi,L]
To parse out the "3-2" from 3-2\.html, you'd use something like:
([0-9])-([0-9])\.html$ That works for two single digits, 0 through 9, separated by a hyphen.
You then back-reference the first digit with $1 and the second with $2 in the substitution URL.
Need more digits? You can specify an upper and lower bound using something like this:
([0-9]{1,4})-([0-9]{1,2})\.html$ That accepts a one-to-four-digit number as $1, and a one-or-two-digit number as $2.
Another way to do this, for example if the parameters are not exclusively numeric, is to accept anything until you find a hyphen and put that into $1, and then accept anything after the hyphen until you find a period and put that into $2:
([^-]*)-([^.]*)\.html$ Ref: [etext.lib.virginia.edu...]
Jim