簡體   English   中英

.htaccess中的RewriteRule循環不起作用

[英]RewriteRule loop in .htaccess not working

我正在嘗試為網站中的所有頁面建立漂亮的鏈接,我想foo.com/services/domestic轉到foo.com/index.php?page=services-domestic 我的.htaccess文件中包含以下內容,對於上面的示例來說,它工作正常,但是如果我嘗試轉到foo.com/services/domestic/case/1 (預期/index.php?page=services-domestic-case-1 )我得到404。

# a/b/c/d -> a-b-c-d
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9_-]+)$ $1-$2 [N]

# a-b-c-d -> index.php?page=a-b-c-d
RewriteRule ^([^(/|\.)]+)$ index.php?page=$1

我試過只重復[N]行3次而沒有標志無效。 除了第一個深度,它沒有任何作用。 可能只是我的業余正則表達式,但我不明白發生了什么變化,有什么想法嗎?

嘗試這個 :

RewriteRule ^([\w-]+)/([\w-]+)$ $1-$2 [N]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1

看來您只需要調整正則表達式並重寫標志:

# a/b/c/d -> a-b-c-d
RewriteRule ^(.*)/(.*) /$1-$2 [L]

# a-b-c-d -> index.php?page=a-b-c-d
RewriteRule ^([^/.]+)$ /index.php?page=$1 [L]

暫無
暫無

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

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