簡體   English   中英

.htaccess在多個查詢字符串中

[英].htaccess in multiple query string

我嘗試使用.htaccess制作干凈的URL。 但是我有多個查詢字符串參數的問題。

我有以下三種URL格式:

 1. http://localhost/websekolah/main.php?page=register
 2. http://localhost/websekolah/main.php?page=detail_news&uid=10
 3. http://localhost/websekolah/main.php?page=gallery&hal=3

我想要這樣的URL:

.    1. http://localhost/websekolah/register
     2. http://localhost/websekolah/detail_news/10
     3. http://localhost/websekolah/gallery/hal/3

我創建此.htaccess,但僅​​適用於1個查詢字符串

RewriteEngine On
RewriteRule ^[css|images|js|config|lib|pages] - [L,NC]
RewriteRule ^(.*)$ main.php?page=$1 [L,QSA]

我在main.php中使用以下方法檢查我的網址重定向:

<?php
    session_start();

    if(isset($_GET['page'])) {
        $page = $_GET['page'];

        $_SESSION['curr_page'] = $page;

        if(isset($_GET['process'])) {

            $process = $_GET['process'];

            if(file_exists("pages/process_$process.php")) {
                include "pages/process_$process.php";
            } else {
                include "pages/404.php";
            }

        } else {
            if(file_exists("pages/body_$page.php")) {
                include "pages/body_$page.php";
            } else {
                include "pages/404.php";
            }
        }

    } else {
        include "pages/body_home.php";
    }
?>

請幫忙,謝謝:)

嘗試改變

RewriteRule ^(。*)$ main.php?page = $ 1 [L,QSA]

RewriteRule ^(。*)$ main.php [L,QSA]

查詢參數仍將在$_GET

用這個:

RewriteRule ^([^/]+)/?$ main.php?page=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ main.php?page=$1&uid=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ main.php?page=$1&$2=$3 [L,QSA]
RewriteRule ^$ main.php [L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM