我是php和htaccess的新手,这是我的第一篇文章。我的网址有问题,我只是想让它干净。顺便说一下,我现在拥有的URL是
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
?>
顺便说一句伙计们。我希望我的网址看起来干净整洁,我还想询问您的建议,我可以做些什么来使我的网站更安全。我希望有人可以帮助我。
答案 0 :(得分:0)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&lesson=$2 [L,QSA]