簡體   English   中英

mod_rewrite RewriteCond和查詢字符串

[英]mod_rewrite RewriteCond and query string

最近,我一直在為客戶做一個小項目。 我正在考慮使用wordpress樣式的漂亮URL格式。 我在Google上搜索了很多,並遇到了Apache的mod_rewrite和RewriteRuleRewriteCond 但是沒有找到任何可以處理隨機參數的示例。 例如:

  • /index.php?param=1 /index/param/1
  • /index.php?foo=bar&hour=1&minutes=12 /index/foo/bar/hour/1/minutes/12
  • /index.php?page=login&attempt=2 /index/page/login/attempt/2

或類似的東西。

如您所見,參數不是固定的。 反正有實現這一目標的方法嗎? 任何幫助將不勝感激。

謝謝

大多數CMS使用PHP來做到這一點。

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

的PHP

$URI = substr($_SERVER['REQUEST_URI'], 1);
$URIparts = explode("/", $URI);

然后,您獲得了URL各個部分的數組,可以根據需要對其進行處理。

暫無
暫無

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

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