Ad

.Htaccess Mod Rewrite File.php To File.xml?

- 1 answer

I have come unstuck with a job im doing that requires some flash xml vars to be loaded by ajax, but I have to generate the xml file with php and for some reason it breaks when i try to jquery load it, but when i changed the extention from php to xml and it worked.

Now I would like to use mod rewrite to rewrite

settings.php?id=1 

to

/1/settings.xml

ive been trying to do it myself using tutorials but i just cant get it right.

Any help would be appreciated.

Ad

Answer

I would like to use mod rewrite to rewrite settings.php?id=1 to /1/settings.xml

which means this:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^([a-z_]+)\.php$ /%1/$1.xml [L]

So when someone requests http://domain.com/settings.php?id=1, they get served the content at /1/settings.xml, but if it's the other way around:

RewriteEngine On
RewriteRule ^([0-9]+)/([a-z]+)\.xml /settings.php?id=1 [L,QSA]

So a request for http://domain.com/1/settings.xml will get served the content at /settings.php?id=1

Since it's never clear what "rewrite <uri> to <another uri>" ever means.

Ad
source: stackoverflow.com
Ad