目前我的网址是这样的
http://localhost/mgosoft/admin/index.php?p=userreg
我想用htaccess重写网址:
http://localhost/mgosoft/admin/userreg/
和链接也将如下所示:
http://localhost/mgosoft/admin/index.php?p=userreg&a=edit
我想改变它:
http://localhost/mgosoft/admin/userreg/?a=edit
的index.php
<?php
error_reporting(E_ALL ^ E_NOTICE);
define('INCLUDE_CHECK',true);
include("mysql.php");
include("logincheck.php");
include("function.php");
if($_REQUEST['p'] == process){
if($_REQUEST['f']){
$fn=$_REQUEST['f'];
$ex=".php";
$file=$fn.$ex;
echo $file;
}
else
header("Location: 404.php");
}
else{
if($_REQUEST['p'] == logout){
session_start();
$userid=$_SESSION['loginuser'];
if(session_destroy()){
$update=mysql_query("UPDATE user SET status=0 WHERE userid='$userid'");
header("Location: login.php");
exit();
}
}
//title start
if(!$_REQUEST['p'])
$title="MyGoaOnline | Goa's Best Search engine | Any Service Provider";
elseif($_REQUEST['p']==home)//change title
$title="Home: MyGoaOnline | Goa's Best Search engine | Any Service Provider";
else
$title=ucwords($_REQUEST['p']);
//body part
if(!$_REQUEST['p'])
header("Location: login.php");
else{
$sql=mysql_query("select id,name,file from menu where name='$_REQUEST[p]'");
$row=mysql_fetch_array($sql);
$count=mysql_num_rows($sql);
if($count==1){
$file=$row['file'];
}
else{
$sql=mysql_query("select name,file,menuid from submenu where name='$_REQUEST[p]'");
$row=mysql_fetch_array($sql);
$count=mysql_num_rows($sql);
if($count==1){
$activeid=$row['menuid'];
$file=$row['file'];
}
else
header("Location: 404.php");
}
}
}
if($_REQUEST['p'] !==process ){
include("header.php");
}
if($file)
include($file);
//footer
if($_REQUEST['p'] !==process){
include("footer.php");
}
?>
答案 0 :(得分:1)
尝试将这些规则添加到/mgosoft/admin/
文件夹中的htaccess文件:
RewriteEngine On
RewriteBase /mgosoft/admin/
RewriteCond %{THE_REQUEST} \ /+mgosoft/admin/index\.php\?p=([^\ &]+)&?([^\ ]*)
RewriteRule ^ /mgosoft/admin/%1/?%2 [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?p=$1 [L,QSA]