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