2014-01-07 24 views
0

我有一个问题,我的网站给我这个网址:mysite.com/?nav=1 & action =收件箱,我想使它友好,像这样:mysite.com/收件箱我的网站与htaccess的友好的URL

如何帮助我?


您好,感谢大家谁帮我,现在我有:mysite.com/1/inbox.html,我想:mysite.com/inbox

+1

请尝试以下方法之一:http://stackoverflow.com/search?q=friendly+url+htaccess –

回答

0

创建一个名为.htaccess文件,并把它放在你的根文件夹:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php [L] 

这基本上说,“如果URL不是一个文件或目录,去的index.php”。

那么你的index.php应该是这样的:

<?php 
    $q = explode("/", $_SERVER['REQUEST_URI']); 
    if($q[1]!=""){ 
    switch($q[1]){ 
     case "articles": 
     include("articles.php"); 
     break; 
     default: 
     include("error-404.php"); 
    } 
    } 
    else{ 
    include("home.php"); 
    } 
?> 

添加新case每个重定向你的需要。并使用$q[2]作为第二个/.../等。