繁体   English   中英

如何重写此代码的URL?

[英]How to rewrite URL for this code?

目前我的网址是这样的

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

?>

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

暂无
暂无

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

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