[英]Url Rewrite in a different way
我習慣於這樣重寫鏈接:
http://example.com/ category / banking-jobs :: RewriteRule ^ category /([[^ /] +)/ $ category.php?id = $ 1 [L]
其中類別是固定的,即網址的一部分是固定的。
當我遇到沒有固定部分的重寫時,我意識到根本不擅長重寫。
http://example.com/year/month/post-name
這意味着年,月,后名可以是任何東西。
請我該怎么辦
編輯:
我有另一種情況,我有另一個網址結構(http://example.com/year/month/day),類似於: http : //example.com/year/month/post-name
但它們應分開處理。 我該如何實現
像您的原始示例一樣,使用占位符([^/]+)
。
RewriteRule ^category/([^/]+)/$ category.php?id=$1 [L]
^ ^
corresponds to | |
| |
http://example.com/category/banking-jobs
因此,對於像這樣的URL:
http://example.com/year/month/day/post-name
您將使用:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ category.php?$1,$2,$3
並且(
括號)
任何內容都會添加另一個枚舉的$4
,然后在重寫的文件名中將其用作¶m=$2
占位符。
您需要這樣的東西。
RewriteRule ^(.+)/(.+)/(.+)/(.+)$ category.php?y=$1&m=$2&d=$3&post=$4 [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.