简体   繁体   English

htaccess为我的网站提供的友好URL

[英]Friendly URL for my web with htaccess

i have a problem, my site give me this URL: mysite.com/?nav=1&action=inbox and i want to make it friendly, something like this: mysite.com/inbox 我有问题,我的网站给我这个URL:mysite.com/?nav=1&action=inbox,我想使其变得友好,就像这样:mysite.com/inbox

How can help me? 有什么可以帮助我的吗?


Hi, thanks everyone who help me, now i have: mysite.com/1/inbox.html and i want: mysite.com/inbox 嗨,谢谢所有帮助我的人,现在我有:mysite.com/1/inbox.html,我想要:mysite.com/inbox

我个人使用生成器进行.htaccess重写。

Create a file called .htaccess and put it in your root folder: 创建一个名为.htaccess的文件,并将其放在您的根文件夹中:

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

This basically says "if the URL is not a file or a directory, go to index.php". 这基本上是说“如果URL不是文件或目录,请转到index.php”。

Then your index.php should look like this: 然后,您的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");
  }
?>

Add a new case for each redirect you need. 为您需要的每个重定向添加新case And use $q[2] for the second /.../ and so on. 并在第二个/.../使用$q[2] ,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM