1

I've always used PHP to include pages into the index file (index.php) but i want a clean URL without using GET method and a SEO friendly solution, i don't now other ways to do this (instead of website.com/index.php?page=about it would be website.com/about) I use PHP in the top of the index.php to tell my website with site shall be picket:

<?php
    $page=$_GET['page'];
        if($page!=''){
            $page=$_GET['page'];
        }else{
            $page="homepage";
        }
?>

And I use this where the page shall be includet:

<?php
    if($page){
        include("pages/".$page.".php");
    }else{
        include("pages/homepage.php");
    }
?>

And my links look like this:

<a href="?page=homepage" <?php if ($page == 'homepage') { ?>class="active"<?php } ?>>forside</a>

I really hope you can give me a good solution, the programming language is pretty much up to you.
Thank you

Jonas
  • 39
  • 5
  • Are you talking about rewriting the URLs to remove the extension? – Matthew Riches Oct 08 '13 at 12:02
  • 2
    Use rewrite, for example if you use apache as webserver: http://stackoverflow.com/questions/8595964/redirect-all-traffic-to-index-php-using-mod-rewrite –  Oct 08 '13 at 12:02
  • I think I now a way to get rid of index.php and the extensions but I don't now another way to include pages. – Jonas Oct 08 '13 at 12:10
  • check this out: http://www.htmlgoodies.com/beyond/php/article.php/3912211/Principles-Of-MVC-for-PHP-Developers.htm – alexg Oct 08 '13 at 12:13
  • Look at using a framework like http://ellislab.com/codeigniter . It uses MVC and can generate nice clean URLs. – nilobarp Oct 08 '13 at 12:16
  • I really hope you will give it a look again, I have edited my question :-) – Jonas Oct 09 '13 at 08:25

1 Answers1

1

From SEO perspective I would rather then having urls in the format http://doma.in/?page=something try to implement them as http://doma.in/something.

To do this you have two options depending on the specific characteristics of your site:

  1. 'static' pages, where the code differs from page to page ('static' php code can still render very vivid output, that changes rapidly based on eg. database input). In this case use

    RewriteEngine on
    RewriteCond  %{REQUEST_FILENAME}  !
    RewriteRule ^(.*)$ /$1.php [L,QSA]
    

    to change the .htaccess or httpd.conf to let apache do all the url tricking for you.

  2. dynamic pages, which are all rendered through the same ONE generic codebase (that is what lots of frameworks do). Follow Redirect all traffic to index.php using mod_rewrite to prepare yourself to support this. In general putting your keyword to page routing into php is more expensive. However this offers lots of flexibility which may be worth to extra ressource.

Community
  • 1
  • 1
Quicker
  • 1,247
  • 8
  • 16
  • I want a dynamic page, where the link looks like website.com/about instead of website.com/index.php?page=about, without redirecting the trafic, It's been set up by PHP GET method witch gives me ?page=about but i only wants about, kan i do this with another method than PHP? Hope you understands – Jonas Oct 10 '13 at 07:26
  • Both my solutions aim at the website.com/about pattern. 'Static' in terms of my answer just means, you have dedicated files per keyword. 'Dynamic' means you implement all logic in just one file. Your code indicates that you have a file per each keyword. So you would run the route, that I labeled with 'static'. – Quicker Oct 11 '13 at 06:39