簡體   English   中英

mod_rewrite-根據URL路徑的規則

[英]mod_rewrite - rule according to url path

我在regex方面非常虛弱,我需要有關執行以下操作的mod_rewrite規則的幫助:

  1. 如果URL僅僅是域名:xyz.com - >去上目錄的index.php像這樣xyz.com/a/index.php
  2. 如果URL包含路徑: xyz.com/abcde- >轉到目錄b上的index.php並將路徑更改為如下所示的參數: xyz.com/b/index.php?id=abcde

目錄a和b當然都在同一根目錄下。

我設法做到了2,但我不知道如何包括規則1。

您可以使用以下內容:

RewriteEngine on
#--if url is just the domain name--#
#--rewrite to /a/index.php--#
RewriteRule ^$ /a/index.php [NC,L]

#--if it contains path--#
#--rewrite to /b/index.php?id=path
RewriteRule ^((?!b).+)$ /b/index.php?id=$1 [NC,L]

暫無
暫無

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

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