I want to add a rewrite rule that will change xyz.xml to xyz.html?type=xml
any ideas if this can be done?
g1smd
5:41 pm on Jul 3, 2011 (gmt 0)
There's somewhere close to 5000 previous threads with examples of how to do this.
Are both of those URLs as used out on the web? Or is one a URL used on the web and the other a filename and parameters used only inside the server?
The answer dictates whether you need a redirect or a rewrite. Both use RewriteRule syntax. One uses the [R=301,L] flags and the other only the [L] flag.
optik
6:08 pm on Jul 3, 2011 (gmt 0)
it's ok I have it
RewriteRule ^(.*)\.(xml) $1.html?$3&type=xml [L]
g1smd
6:13 pm on Jul 3, 2011 (gmt 0)
Several Errors.
The (.*) is the WRONG patttern as it matches the whole request then has to "back off and retry" hundreds of times to find out what you actually meant.
You need to add a leading slash before $1 unless you want to expose your site to some serious hacks.
$3 is undefined. Only two backreferences are created from the RegEx pattern.
actually one thing that's missing is I need the variables passed to the new string like I had here html?%1&changed=true
lucy24
3:23 pm on Jul 18, 2011 (gmt 0)
That's what QSA is for. It stands for "query string append" and means add "changed=true" to the existing query string instead of replacing it with "changed=true".
By default, nothing that happens in a rewrite affects the query string. To change the query you have to do one of three things:
if the target ends in ? alone, it means delete the existing query
if the target ends in ?{morestuff} it means replace the existing query with {morestuff}, or create a new query if it wasn't there before
if the target ends in ?{morestuff} and you say [QSA] it means add {morestuff} to the existing query
The braces {} are not part of the Regular Expression, they are just my notation.