homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Serving XML to the SEs via PHP
Will this cause problems?

 6:35 pm on Dec 4, 2002 (gmt 0)

I want to produce content for a theme based site in XML. I know I can serve XML to the Client via PHP and the Expat Library functions.

The issue I'm grappling with is that the most effecient method would be to write one template file and parse the various XML files as needed. The problem is that the SEs will only see the template file.

So what I'm looking for is a way to show links to the Search Engines that look like somefile.xml or somefile.html and when activated, run the template script and deliver the correct HTML.

I've heard this could be done via .htaccess and/or mod_rewrite. Before I go try to figure out exactly what I need to do, I'd like to know if:

1. what I want to do makes sense
2. may get me into trouble with the SEs
3. could be done differently/more efficiently

As always, your insight would be most appreciated!



 7:05 pm on Dec 4, 2002 (gmt 0)

you could also do the same effect as mod rewrite with your php. The url could be parsed and then used as vars for your queries.


php reads the url, cuts out $cat = cat1 and $sub = sub1 and then goes and finds all the info about it. I do this for menus and content a lot. The script figures out where it is in the directory structure and loads all pertinent info based on the url.

Similar to mod_rewrite and similar to get strings but all done with pure php and mysql.


 7:14 pm on Dec 4, 2002 (gmt 0)

I'm sorry jatar_k but I'm not following you.

If I have a link with "www.mydomain.com/somefile.xml" how would I know to use the php template file to parse the XML file using PHP? Something has to call the parser.


 7:28 pm on Dec 4, 2002 (gmt 0)

when I can't or don't want to use mod_rewrite I often have to fake it. I create the directory structure, in the file I include the template/script. It then reads the url it was called from and does whatever it needs to do based on the url.

I don't know, maybe mod_rewrite is easier depending on the number of pages/links you need to have.

Just the way I have done things a lot of times, it seems to make perfect sense when it's in my head but I don't seem capable of explaining today. Think I will have to get more coffee.

I guess my answers to your questions were something like this
1. yes
2. no
3. differently - yes
more efficiently - don't know, probably equal


 8:08 pm on Dec 4, 2002 (gmt 0)

Thanks jatar_k

Back on the mod_rewrite:

Would this be the right direction to head in?

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo\.html$ foo.php?f=foo.xml [T=application/x-httpd-cgi]


 11:19 pm on Dec 4, 2002 (gmt 0)

You donīt need to add the MIME type when the server is configured to let PHP handle .php files.

BTW if you want to use mod_php then the MIME type would need to be application/x-httpd-php not application/x-httpd-cgi.

If all your pages are produced by the same script then a rewrite rule like this will be more generic.

RewriteRule ^(.*)\.html$ foo.php?f=$1.xml



 1:10 pm on Dec 5, 2002 (gmt 0)

Thanks Andreas,
I should have cleaned that up a bit before I posted it but I just wanted to know if it would be problematic with the SEs.


 1:22 pm on Dec 5, 2002 (gmt 0)

There wonīt be any problems if the SEs see ordinary links like foo.html.

BTW do you serve XML directly to the client or do you transform it on the server and then serve HTML as you do for the SEs?



 4:23 pm on Dec 5, 2002 (gmt 0)

The current game plan is to parse the XML using PHP's Expat Library and XSLT. That's why I needed to use mod_rewrite in .htaccess so that when a .html or .xml file of a certain type is requested, the script is initiated and serves up the correct HTML version.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved