簡體   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