Php 如何重写此代码的URL?

Php 如何重写此代码的URL?,php,.htaccess,rewrite,Php,.htaccess,Rewrite,目前我的URL是这样的 http://localhost/mgosoft/admin/index.php?p=userreg 我想使用htaccess重写url: http://localhost/mgosoft/admin/userreg/ 链接也将如下所示: http://localhost/mgosoft/admin/index.php?p=userreg&a=edit 我想这样改变它: http://localhost/mgosoft/admin/userreg/?a=ed

目前我的URL是这样的

http://localhost/mgosoft/admin/index.php?p=userreg
我想使用htaccess重写url:

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");
}

?>

尝试将这些规则添加到
/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]

您的查询存在SQL注入漏洞,因此请确保在启用此查询之前修复它们。这是本地软件。。。它不在服务器上运行。。。谢谢你的建议