.htaccess htaccess重写规则-清除url

dtcbnfnu  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(164)

我正在寻找在我的网站是建立在PulseCMS清理网址。
目前,在博客文章中,url包括blog一词、文章编号和文章标题,标题为“This,is a sample - Title”https://example.com/blog-10-this,-is-a-sample---title时,url可能看起来像这样
我愿意
1.在blog一词和标题之间放置一个“/”-使其成为“domain.com\blog\title”
1.删除博客编号-因此删除“-10”,并
1.从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]

任何帮助都将不胜感激!

sqxo8psd

sqxo8psd1#

根据要求和跟进意见,您可以使用以下规则:

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]

相关问题