Serving different XML content on the same web - php

I don't know if this is the suitable place to ask this question, so I am sorry if I am doing it wrong. I think this is not a duplicate question. If it is, I am sorry too.
Currently, I have a web app which takes its content from a unique XML document. The URL is "http://webapp.com/"
The problem is that now I have to create a second version of the web which uses a new different XML document, so I have to put them different URLs, something like the following:
http://webapp.com/activities
http://webapp.com/stages
How can I have all my sources on just one directory on server-side (I suppose it's better to maintain, the resources are cached better, etc...) but with these 2 URLs pointing to the folder and making the PHP loades the XML depending on the URL?
I suppose I have to change the .htaccess file to redirect to that folder, but how can I tell what XML I must load? And the user must see on the search bar the URL he used, for example "http://webapp.com/activities"
Can anybody help me please?
Thanks for all

You can use a .htaccess rule to redirect a URL like http://webapp.com/{anything} to http://webapp.com/?q={anything}. Then in your script you can write conditions based on $_GET['q'] and load different XML. That is if I understand your question right.

Related

Purpose of replacing .php with .html extension through .htaccess file

I was reading a little about .htaccess file and I found that it's possible to change .php in the url to .html
But I do not understand what the point of doing it is or what it tries to achieve.
Please note that i'm a beginner with .htaccess also I've searched for that on Google but I didn't found what i'm looking for
There is an ever ongoing battle between seo friendly url's and not. It all depends on the very purpose of your site. If for an example you have a script with dynamic pages like search script or generator of some type (very broad , right ? ;) ) then if your url looks like this:
domain.tld/products?id=183
Rather than
domain.tld/products|183.html
then I don't think there is any better than .php, it's still dynamic and SE will discover that but if you have blog then you might consider a proper wording in url instead of id's. I can think of only one reason apart from what SE' see. What your viewer/surfer sees. I think if he quickly glance at domain.tld/date/rather-simple-title then he might be more interested than in id=183. Now if the url has extension domain.tld/date/rather-simple-title.php or domain.tld/date/rather-simple-title.html in my humble opinion there's no impact on either SE or your website visitor.
Pure theory and rather opinion based conversation here, like the question.

How to format the retrieve MySQL data to make it like a subdirectory of a domain using PHP

I am very curious on how to make a site built using php and mysql. When i try to retrieve username from mysql how can i format it like this, very similar to facebook or twitter (note: i am not making social networking site here, i just like the idea and i think it is very helpful)..
mydomain.com/username
at first, i thought i should make a sub-directory to all the usernames.. but wait, what if i have tons of usernames in the database how can i make directories in each usernames? so i think somebody might help me here..
or like on a blog.. how can i make the title of the post like this:
mydomain.com/title-of-the-post
i'm new to php..
you can freely edit this question if this is ambiguous or not easy to understand i just can't find the exact word for this..
You need a router [e.g. klein], and to apply the Front Controller Pattern in order to route all incoming requests to the entrance of your application.
No directory nor filesystem should be involved at all.
You write a PHP routine to parse the URL.
So that the URL reaches the PHP routine, you make all /username, /title-of-post etc point to this routine using .htaccess - typically directing all traffic for anything that doesn't exist as a file or directory to your index.php file.

PHP CMS web page short URL?

I am buildiig a simple CMS and would like to know how to create short URLs (not the APACHE bit but the PHP bit).
example.com/?page=100
example.com/home/test
How would I interpret the ?page=100 into /home/test (Through select the database, but i couldn't figure out how) I can see if just one level /home/test because you probably can have a zoneID, but when it comes to /home/test/test. I become lost
And how do I parse back the /home/test to the page id.
Plus is there anyone can show a bit idea for the database design as well?
These resources can be useful to you:
https://stackoverflow.com/a/120411/370290
http://www.symfony-project.org/book/1_0/09-Links-and-the-Routing-System
http://codeigniter.com/user_guide/general/urls.html
http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/
You need some kind of mod_rewrite for your server side.
That will help you to send route data to index.php (or somewhere else) file without filename in adress string. Than some php file will analyze the route and give correct html.
ok i think you need to definitely need to look at the way you are going to do your routing (through mod_rewrite)..for example
1.you can rewrite the page www.example.com/test to ..www.example.com/index.php?page=test and implement a way of getting page by the page name..and returning an id if a page name exists ..if multiple entries exist then maybe the last modified will be given precedence over the otheers ..you can get the following book CMS Design Using PHP and jQuery helped me alot

Converting site from .html to .php

my site has now become sufficiently large for me to think it's necessary to convert the pages to php pages to help me update it in the future. The problem is: my site has a number of links to it on various websites across the web. Eg these links point to www.example.com/page1.html but the page is now going to be renamed www.example.com/page1.php
How would people get around this problem? Simply redirect the html page to the php page? Are there any alternatives? Does this have any implications for SEO?
Thanks
URL Rewrite: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
More directly to the point: http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html
The least intrusive method is to simply have your webserver treat .html files as PHP files. That way your links can stay intact, and progressively replacing static .html pages with actual php-enabled pages can be done in an essentially transparent method to users.
Remember, there is no such thing as a "PHP script". There are only files that contain <?php ... ?> code blocks, which will get interpreted/executed when the containing file is passed through PHP.
Unless some of your html pages contain SAMPLES of php code that could be misinterpreted as actual code, then there shouldn't be any issues with making run through PHP.
As a minor side benefit, it wouldn't be immediately obvious that your site is running on PHP, as all the urls would say ".html". But then, that's security by obscurity and shouldn't be counted on to be anything in the way of real security.
You can do a 301 redirect (this works fine for SEO), or just rewrite the URLs so page1.html points to page1.php internally.
Both solutions can be done with the .htaccess file (assuming you are using apache as your webserver)
Maybe consider using a tool such as Dreamweaver to manage your website. That way you can easily rename pages and update the links with a few clicks.
:)
As answered by Marc B,
there is no such thing as a "PHP script". There are only files that contain code blocks, which will get interpreted/executed when the containing file is passed through PHP.
i would say that it's true and if you want to absolutely turn your html files into php files simply put <?php before your <DOCTYPE html!> line and then ?> after your </html> line save it and rename it as example.php if it is example.html
if you are windows8 or higher user then click on 'View' in file explorer and then check 'File name Extension'. Now you'll be able to see the extension example.html and many other files extensions like .jpg, .mp3 e.t.c...., This helps you to easily rename exactly like example.php but not example.php.html as .html will not be visible if you are not checked File name Extension.
I would suggest that you use CodeIgniter (kickass php framework).
You can maintain the existing site structure also, by making use of CodeIgniter's URL suffix option .

Create Pages Automatically

Is there any method in Php by which I can create a page automatically based on a predefined template. Like if we create a new post in blogger it automatically creates page for that post with the name of that post, like this one:
http://learntoflash.blogspot.com/2009/12/exit-button-in-flash.html
Here Exit Button In Flash is the name of my post I have written and an automatic page is created for it.
Or like here on this website if we ask a question it automatically creates a page for that question. I want to know can I achieve this in Php or anything close to this ?
...here on this website if we ask a question it automatically creates a page for that question.
It sounds like you may believe an actual file is created when you post a question. My bet would be that this page is generated via the question id in the URL.
The only files created would be cached output, which may or may not resemble actual HTML pages.
You should use URL rewriting. This Apache module lets you define rules to rewrite web addresses in your desired way.
The process to make your web application ready for this, is not a short story so you should read more about it.
This article is a good starting point:
http://articles.sitepoint.com/article/guide-url-rewriting
This is acheived by using mod_rewrite. A good place to look for inspiration is the .htaccess used in Wordpress.
to something like that you have to grasp the very fundamental in php or any programming language at all, i mean the core of php is to create dynamical generated pages based on user/browser input.
You might need to take a quick tutorial about php might I suggest http://www.tizag.com/phpT/
good step for step tutorial
Edit:
if you're wondering how the websites seems to have created a html page for every question, the answer would be they're not they are probably using mod_rewrite as mentioned before to rewrite to url to print a little more user friendly url, the actual url could be something like this https://stackoverflow.com/index.php?post=4499289 in reality

Categories