1
代替下劃線,我需要改變以下網址htaccess的文件,刪除文件夾,並用破折號
http://somedomain.com/news/a_sample_news_article.html
到
http://somedomain.com/post/a-sample-news-article
我在我的htaccess其作品有這一點,但我相信它可以改進 - 有沒有人有更好的解決方案?
RewriteEngine on
# replace underscores
RewriteRule ^(news)/([^_]*)_+(.*)$ /$1/$2-$3 [L,NC,R=302]
# redirect the directory from news to post
RewriteRule ^news/(.*)$ /post/$1 [R,L]
# remove .html from end of url
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
任何幫助非常感謝!
非常感謝回報 - 作品很棒。在這些規則的背景下,從原始網址中移除.html的最佳方式是什麼? – Newfoundland