简体   繁体   中英

How to rewrite URL for this code?

Currently my URL is like this

http://localhost/mgosoft/admin/index.php?p=userreg

I want to rewrite url using htaccess:

http://localhost/mgosoft/admin/userreg/

and link will also look like this:

http://localhost/mgosoft/admin/index.php?p=userreg&a=edit

I want to change it like this:

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

?>

Try adding these rules to the htaccess file in the /mgosoft/admin/ folder :

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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