[英]Movable Type: remove part of URL using regex replace
我想使用我在下面嘗試過的regex_replace刪除部分uf url,但無法正常工作。 我正在嘗試刪除“ index1.php”
代碼輸入:
http://www.myblog.com/blog/content/fruit/index1.php
我的密碼
<mt:getvar name="permalink" regex_replace="/index1\.(php)$/","">
代碼輸出:
http://www.myblog.com/blog/content/fruit/index1.php
但這應該是
http://www.myblog.com/blog/content/fruit/
嘗試以下模式:
<mt:getvar name="permalink" regex_replace="/\/[^\/]+$\/","">
或者,嘗試使用捕獲組:
<mt:getvar name="permalink" regex_replace="/(.*\/)index1[.]php$\/","$1">
對於您發布的示例,您無需使用regex_replace
,只需使用replace
:
<mt:GetVar name="permalink" replace="index1.php","">
尚不清楚您是否計划使用regex_replace
實際進行正則表達式匹配(也許數字有所不同),但如果沒有,則替換更容易,更快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.