簡體   English   中英

URL中的index.php時進行mod-rewrite

[英]mod-rewrite when index.php is in the URL

我希望將http://example.com/admin/pages/index.php重寫為http://example.com/index.php?admin=admin&cid=pages

它適用於http://example.com/admin/pages (我也想要),但不適用於http://example.com/admin/pages/index.php

如何完成的?

在RewriteBase上的RewriteEngine /

# If the request is for a valid directory, file, or link, don't do anything
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

#remove the trailing slash
RewriteRule (.+)/$ $1

# If you add this first rule to support views, be sure to remove the QSA flag from the second rule (maybe not required since the first rule has the L flag)
#replace admin/cid with index.php?admin=admin&cid=cid
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?admin=$1&cid=$2 [L,QSA]
#replace mypage with index.php?admin=mypage
RewriteRule ^([^/]+)/?$ index.php?admin=$1 [L,QSA]

編輯

隨機變化表明這可能是正確的。

    RewriteRule ^([^/]+)/([^/]+)/index.php/?$ index.php?admin=$1&cid=$2 [L,QSA]
    RewriteRule ^([^/]+)/([^/]+)/?$ index.php?admin=$1&cid=$2 [L,QSA]
    #replace mypage with index.php?admin=mypage
    RewriteRule ^([^/]+)/index.php/?$ index.php?admin=$1 [L,QSA]
    RewriteRule ^([^/]+)/?$ index.php?admin=$1 [L,QSA]

問題是您的第一個規則是從規則中跳過所有文件和目錄。

用以下內容替換規則:

RewriteEngine On

RewriteRule ^index\.php$ - [L,NC]

#remove the trailing slash
RewriteRule (.+)/$ $1 [L,R=302]

# If you add this first rule to support views, be sure to remove the QSA flag from the second rule (maybe not required since the first rule has the L flag)
#replace admin/cid with index.php?admin=admin&cid=cid
RewriteRule ^([^/]+)/([^/]+)(?:/?|/index\.php)$ index.php?admin=$1&cid=$2 [L,QSA]

#replace mypage with index.php?admin=mypage
RewriteRule ^([^/.]+)/?$ index.php?admin=$1 [L,QSA]

暫無
暫無

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

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