我正在考慮清理我的網站中的網址,該網站內置于 PulseCMS 中。
目前在博客文章中,url 包括單詞 blog、文章編號和文章標題,可能看起來像這樣,標題為“This,is a sample - Title”
https://example.com/blog-10-this,-is-a-sample---title
我想
- 在單詞 blog 和標題之間放置一個 '/' - 讓它變成 'domain.com\blog\title'
- 洗掉博客號 - 所以去掉“-10”,然后
- 從 URL 中洗掉 ',' 和額外的 '-'。
所以以以下結束
https://example.com/blog/this-is-a-sample-title
我目前的 htaccess 重寫規則是這樣的,我不知道從哪里開始..
RewriteRule ^blog-page-([^-]*)$ ?page=$1&p=blog [L]
RewriteRule ^blog-([^-]*) ? ?d=$1&p=blog [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L]
任何幫助是極大的贊賞!
uj5u.com熱心網友回復:
根據要求和后續評論,您可以使用以下規則:
RewriteEngine On
# redirect from
# /blog-10-this,-is-a-sample---title
# to /blog/10/this,-is-a-sample---title
# executes repeatedly as long as there are multiple , or -- in URI
RewriteRule ^(blog-\d )[,-] (.*?)(?:,|-{2,})(.*)$ $1-$2-$3 [N,DPI]
# redirect to clean URL
RewriteRule ^(blog)-(\d )[,/-] (.*) /$1/$2/$3 [L,R=302,NE,NC]
# rewrite /blog/10/title
RewriteRule ^blog[/-]([^-] )/ ?d=$1&p=blog [L,QSA,NC]
RewriteRule ^blog-page-([^-]*)$ ?page=$1&p=blog [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/495766.html