0
votes

I'm realizing a php website and I'm trying to split all the files in a way that should give me the possibility to update them easily. In the current structure I've:

  • header.php
  • menu.php
  • footer.php

These files are included in the following pages:

  • page1.php
  • page2.php
  • page3.php

On each one of the pages above I write specific content. At the end my urls are:

http://www.example.com/page1.php http://www.example.com/page2.php http://www.example.com/page3.php

But what I would like to do is to reproduce the wordpress structure that uses index.php only as output.

So, just to go more in detail, I would like to realize an index.php inside of which I'll include just one time:

  • header.php
  • menu.php
  • footer.php

and including the page1.php content, the page2.php content and the page3.php content. At the end I need to have as URL a permalink that says:

http://www.example.com/page1 http://www.example.com/page2 http://www.example.com/page3

I've checked on the web but seems there's nothing online useful for my needs and when I check "permalinks" users talk only of wordpress. Could you help me please on this activity? Tell me if my request is not so clear or I'm wrong on something. Thanks!

2
You need mod_rewrite, see some examples: workingwith.me.uk/articles/scripting/mod_rewrite - one of examples solves your problem -> index.php page with page parameter... - sinisake
Great! Following your link I was able to satisfy my request! Thanks :) - mauro269

2 Answers

1
votes

Thanks to the link suggested by @nevermind I solved the issue. Below the solution...

  1. I created a .htaccess file with inside the following code:

RewriteEngine on
RewriteRule ^page/([^/.]+)/?$ index.php?page=$1 [L]

  1. I created an index.php file with the following code:

<html>
   <head>
      <title>Test Page</title>
   </head>
   <body>
      <?php include $_GET['page'].'.php'; ?>
   </body>
</html>
  1. I uploaded the two files in the same folder (/test/) together with the file "introduction.php".
  2. Considering I wanted to open the page "introduction.php" I pasted the following URL in the browser:

http://www.example.com/page/test/introduction

That's all! Thanks guys for your support. I hope this can help other users looking for the same solution.

0
votes

page#.php will have to be like this:

 <?php 
   include_once('header.php');
   include_once('menu.php');
   //body content of page#
   include_once('footer.php');
 ?>

you will still have 3 files with the same url but the header ,footer and menu will be the same across the pages