Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite a php file to a xml

         

debianer

11:33 am on Jun 19, 2013 (gmt 0)

10+ Year Member



Hello Forum,

I am trying to to rewrite /mail/config-v1.1.xml to autoconfig.php and saving possible parameters like "?emailaddress=name@doma.in", so that "http://domain.de/mail/config-v1.1.xml?emailaddress=name@doma.in" leads to "autoconfig.php?emailaddress=name@doma.in"

But the parameters should be optional; that is what I am trying in the first rule.

RewriteEngine on
RewriteRule ^/mail/config-v1\.1\.xml(\?)?(.*)$ /autoconfig.php [L]
RewriteRule ^/mail/config-v1\.1\.xml\?emailaddress=(.*)$ /autoconfig.php?($1) [L]

phranque

12:01 pm on Jun 19, 2013 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, debianer!


you cannot examine the query string in the RewriteRule Pattern - you have to use a RewriteCond directive for that.
however in your case, you aren't testing or capturing anything in the query string, you are reusing all of it - intact.
by default, the query string is passed through unchanged.

also, depending on the context in which your RewriteRule is implemented, the path information of the request can be modified by the server's mod_rewrite processing.
if your RewriteRule is in the .htaccess file of the document root diretory, then the leading slash will be stripped from the requested url.

assuming this, you probably are good with something like this:
RewriteEngine on
RewriteRule ^mail/config-v1\.1\.xml$ /autoconfig.php [L]

debianer

2:18 pm on Jun 19, 2013 (gmt 0)

10+ Year Member



Hi phranque,

thanks for your fast reply and the warm welcome. Your ruleset help me achieving my goal.