[英].htaccess Clean Url with multiple parameters
我是php和htaccess的新手,這是我的第一篇文章。 我的網址有問題,我只是想使其整潔。 順便說一句,我現在擁有的網址是
http://www.example.com/index.php?page=home&lesson=1.1
我如何將其更改為
http://www.example.com/home/1.1/
這是我的index.php
代碼
<?php
include("page_check.php"); // this is where the program check what is the requested page.
include($page); // it could be home.php, login.php and etc
include("templates/layout.php"); //the template, contains HTML tags...
?>
page_check.php
代碼...
<?php
session_start();
$page = $_GET['page'];
$array_page=array('home','create_group','group','try_it_out','logout');
$page_no_session=array('login','register','email_confirmation');
$len;
if (!empty($_SESSION['login_state'])){
$len = count($page_no_session);
for($i = 0; $i < $len; $i++){
if ($page_no_session[$i] == $page){
$page = "home";
}
}
if(empty($page)){
$page = "home";
}
}
else{
if(empty($page) AND empty($_SESSION['login_state'])){
$page = "login";
}
else{
$len = count($array_page);
for($i = 0;$i < $len;$i++){
if ($array_page[$i] == $page){
$page = "login";
}
}
}
}
$page = "$page.php"; //this is what I'm telling, it could be home.php, login.php and etc.. defends upon the requested php file
?>
伙計們 我希望我的URL看起來干凈整潔,也想征詢您的建議,我還可以采取其他措施使我的網站更安全。 我希望有人可以幫助我。
您可以在DOCUMENT_ROOT/.htaccess
文件中使用以下代碼:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&lesson=$2 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.