0

So, this will be very basic question.

I am new to php.

So, let say my domain name is example.com. And I have 4 php files for 4 different pages:

intro.php for example.com/intro

welcome.php for example.com/welcome

computer.php for example.com/computer

phone.php for example.com/phone

The question that I have is that how do I create different children url based on the php files that I have? So that appropriate files will be called when an user visits the url.

What is the structure?

Thanks

HEYHEY
  • 533
  • 4
  • 13

3 Answers3

0

Perhaps you need somthing like routing?

See this link here for a start or:

http://blogs.shephertz.com/2014/05/21/how-to-implement-url-routing-in-php/

a framework would do the routing for you if you don't want to do it yourself.

Did that help you?

Kind Regards

Kilian Hertel
  • 166
  • 1
  • 14
0

Try this Htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\\.php [L]

or

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php

You still have to change all the links on your site to point to the new URLs.

Vadivel S
  • 660
  • 8
  • 15
0

I think the easiest way would to make a html form with a method "get" that way you submit a form with a query string. Say you have a web app which has articles, you can have a page that processes the articles, say, "single_post.php". From index.php you can have

<form action="single_post.php" method="get" ><input type="hidden" name="key" value="<?php $key ?>" /><button type="submit">Read article</button></form>

In single_post.php you get:

<?php $key = $_GET['key'] ?>

Then you can use php to manipulate the page as you see fit.

AntonyMN
  • 660
  • 6
  • 18