Xml file

software development


i have two identical files with different extensions. one .xml and another .php. But the file with the .xml extension returns error.

I tried creating a htaccess file whith the forcetype directive but it fails.

can anyone help me?!


so the xml file actually contains php content? you can tell apache that xml files should be parsed as php by putting this line in .htaccess (assuming you’re running php5-cgi, the default):

AddHandler php5-cgi .xml

what i often do though is actually have the file named .xml.php (if i wanted to use php to generate xml) and then use mod_rewrite so that requests for filename.xml actually went to filename.xml.php:

RewriteEngine on
RewriteRule ^filename.xml$ filename.xml.php

track7 - my dream-hosted site


If you’re going to do this with a lot of files and URLs, but don’t for some reason see fit to switch to a CMS (which could take of all the URLs and extensions for you), this also works:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [QSA]

The result is that whenever you enter “…/file.html” or “…/file.txt” etc. in the address, and file.html or file.txt don’t exist, the server then checks if file.html.php or file.txt.php exist, and returns that.