Forum Moderators: phranque
and a request like this
[mysite.com...]
Having read the cryptic mod rewrite documentation at
[httpd.apache.org...]
I expected to execute the sript at dodah.php
with a query string of a=1
Instead I get an error
The requested URL /a=1 was not found on this server
So obviously QSA has little to do with the Query String and instead simply replaces the url as if the QSA were not there.
QSA appends the original query string to the end of the rewritten URL. So if you requested http://www.mysite.com/a1.htm?myvar=true, and had the following rules:
RewriteEngine On
RewriteRule .* dodah.php [QSA]
Then the rewritten URL would be http://www.mysite.com/dodah.php?myvar=true
If you are simply wanting to append a query string, you could do so like this:
RewriteEngine On
RewriteRule (.*) $1?a=1
Chad
You can definitely do that. For instance, I could build a query string of "A=1&B=2&C=3" with the following rules:
RewriteEngine On
RewriteRule .* dodah.php?A=1
RewriteRule .* dodah.php?B=2 [QSA]
RewriteRule .* dodah.php?C=3 [QSA]
One this to remember is, each rewrite changes the request. So, let's say I want to rewrite everything to dodah.php, and append "t=1" to any URL with the string "test" in it, and "type=htm" to any URL that ends with htm. The following would not work, because it would never match the test or htm:
RewriteEngine On
RewriteRule .* dodah.php
RewriteRule test dodah.php?t=1 [QSA]
RewriteRule htm$ dodah.php?type=htm [QSA]
Instead, you have to look at THE_REQUEST variable, like this:
RewriteEngine On
RewriteRule . dodah.php
RewriteCond %{THE_REQUEST} ^(GET¦HEAD¦POST)\ .*test [NC]
RewriteRule . dodah.php?t=1 [QSA]
RewriteCond %{THE_REQUEST} ^(GET¦HEAD¦POST)\ .*htm$ [NC]
RewriteRule . dodah.php?type=htm [QSA]
Keep in mind that the vertical bars should be pipes (WebmasterWorld rewrites them). Hope that helps.
Chad
my new URL will look like this:
www.mysite.com/-a1-b2-modelpage.htm
I added the - in front of the parameter to make sure they didn't match on just any a-e followed by a number as in page1.htm
The generated URL should be:
www.mysite.com/dodah.php?a=1,b=2,page=modelpage.htm
But alas I get:
www.mysite.com/dodah.php?a=1&b=2&page=modelpage.htm
Which is not too bad considering that I did nothing to insert the ampersands or commas.
I am not sure from where the ampersands came but I need to make them int commas.
I have the following code in .htaccess
and it almost works, except that it puts an & between the output parameters where I would like a comma.
After three full days of mod rewrite my head is swimming, I cannot even figure out how to change the Ampersands to commas?
Will you help just once more?
====================================================
RewriteEngine on
RewriteRule . dodah.php?
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-([a-z][a-z0-9]+\.htm)
RewriteRule . dodah.php?page=%2
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-([a-z][a-z0-9]+\.html)
RewriteRule . dodah.php?page=%2
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-f([0-9]+) [NC]
RewriteRule . dodah.php?f=%2 [QSA]
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-e([0-9]+) [NC]
RewriteRule . dodah.php?e=%2 [QSA]
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-d([0-9]+) [NC]
RewriteRule . dodah.php?d=%2 [QSA]
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-c([0-9]+) [NC]
RewriteRule . dodah.php?c=%2 [QSA]
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-b([0-9]+) [NC]
RewriteRule . dodah.php?b=%2 [QSA]
RewriteCond %{THE_REQUEST} ^(GET劣EAD同OST).*-a([0-9]+) [NC]
RewriteRule . dodah.php?a=%2 [QSA]