管理网页和URL

时间:2013-05-23 08:24:32

标签: php url-rewriting

我有一个像这样的网站树

  1. controller(文件夹)

      

    file1.php
    file2.php
    .....
    file10.php

  2. view(文件夹)

      

    home.php
    profile.php
    message.php
    的login.php
    register.php
    .....

  3. index.php
  4. css.css
  5. js.js

  6. 目前index.php很常见,它包含用户想要的页面 www.mysite.com/?show=profile 首先,我要验证变量show,并在index.php

    上添加相应的页面

    的index.php

    $show=$_GET['show'].".php";
    include("view/".$show);
    

    但是我不希望我的网址像www.mysite.com/?show=profile这样,我希望如果用户john点击页面profile,那么我的网址应为

    www.mysite.com/john/profile/
    

    正如我所知道的那样:转到文件夹john然后转到profile,最后转到index.php
    我是否必须为每个用户制作每个文件夹和文件,或者有什么办法可以使用现有的网站树来完成它?

    我希望你理解我想说的话:(

    感谢名单

1 个答案:

答案 0 :(得分:1)

您需要使用.htaccess文件来创建漂亮的网址:http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/

编辑:我看起来像这样:

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|png|gif|ico|swf)$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+) index.php?params=$1&%{QUERY_STRING} [L]