簡體   English   中英

mod_rewrite RewriteCond匹配根目錄+文件名

[英]mod_rewrite RewriteCond match root directory + file name

我無法轉換以下鏈接

http://example.com/test              

http://example.com/pages.php?p=test

但后來沒有轉換以下鏈接

http://example.com/foo/test (http://example.com/foo/pages.php?p=test)
http://example.com/bar/test (http://example.com/bar/pages.php?p=test)

我目前的設置如下:

RewriteCond %{DOCUMENT_ROOT}/$1 !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php !-f
RewriteCond %{REQUEST_URI} ^/$1$
RewriteRule ^([^\.]+)$ pages.php?p=$1 [NC,L]

我似乎遇到了最后一個RewriteCond (RewriteCond %{REQUEST_URI} ^/$1$)似乎沒有檢測到URL更改。 有任何想法嗎?

要將/ test轉換為/pages.php?p=test,您可以使用以下規則:

 RewriteEngine on
 RewriteRule ^([^/.]+)$ /pages.php?p=$1 [NC,L]

暫無
暫無

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

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