2

I would like to make a website that is php and only requires one php document to display the content. It's kinda hard to explain, so let me try my best.

Some websites use a directory based system such as this:

web.URL.com/index.htm
web.URL.com/about.htm
web.URL.com/blog.htm

and so on. This involves creating a text file for each page.

So, the goal here is to create one page that acts like a frame, and displays content based on the Url, so it will be acting like the above method, but is only one page. I'm pretty sure you can do this, but don't know the proper way to word it or what vocabulary to use when typing it in to google.

Some questions you may have:

Q:Why not use parameters like this:

web.url.com?pgid=some+page

A: I would like the url to be as clean as possible when it comes to the visitor typing the url. For example, this is much easier to remember:

web.url.com/about

than this:

web.url.com?p=about 

Q: Wordpress??

A: We want our own stuff. Wordpress is great, but not for our project.

Q: JQuery?

A: PHP please.

Thank you in advance!

2
  • JQuery is clientside, not serverside. You can utilize PHP and jquery together... Commented Jan 2, 2012 at 19:03
  • possible duplicate of Clean URLs - How do I accomplish this? Commented Jan 2, 2012 at 19:10

4 Answers 4

5

With PHP alone, I don't think it's possible. However, it's likely that your webserver is running Apache, which makes this task fairly straightforward by transforming your pretty URLs into ugly URLs (with query strings) that your PHP script can handle. Your visitors have no idea this is happening; they aren't redirected or anything.

I strongly recommend you take a look at this tutorial, and its followup. The second tutorial contains the information you need for this task (starting in this section), but I strongly recommend reading the first tutorial to gain a deeper understanding of what you're doing.

Essentially, those tutorials will teach you how to specify (ugly, scary-looking) URL-rewriting rules in a file called .htaccess. These rules will transform (or "rewrite") your pretty URLs into less pretty ones that your PHP script can handle.

For example, yoursite.com/about would actually be accessing yoursite.com/index.php?page=about, or something along those lines.

For some sample code, here's a snippet 95% copied and pasted from this tutorial:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

As that link explains, it will forward all requests to index.php, unless an actual file or directory is being requested.

Sign up to request clarification or add additional context in comments.

Comments

1

Use a RewriteRule based .htaccess. Then you can have all non-existing files redirected (internally in Apache) to a general index.php with the requested path as a query string ?p=about. The redirecting is handled internally, so http://example.com/about is the external URL to that page.

Comments

0

You can have a switch statement checking $_GET values and output the page based on the provided parameter. Also, you will have to add some mod_rewrite rules to route those requests.

Comments

0

Use PHP URL rewrite. PHP will enteprate part of your URL as query string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.