Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess文件以删除文件夹,并用破折号替换下划线_.htaccess - Fatal编程技术网

.htaccess htaccess文件以删除文件夹,并用破折号替换下划线

.htaccess htaccess文件以删除文件夹,并用破折号替换下划线,.htaccess,.htaccess,我需要更改以下url http://somedomain.com/news/a_sample_news_article.html 到 我的htaccess中有这个功能,它可以工作,但我相信它可以改进-有人有更好的解决方案吗 RewriteEngine on # replace underscores RewriteRule ^(news)/([^_]*)_+(.*)$ /$1/$2-$3 [L,NC,R=302] # redirect the directory from news to po

我需要更改以下url

http://somedomain.com/news/a_sample_news_article.html

我的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] 
非常感谢任何帮助

重定向

  • /新闻/美食酒吧

  • /邮政/富吧
您可以使用以下规则:

RewriteEngine on

# redirect "/news/foo_bar" to "/foo_bar"    
RewriteRule ^news/(.+)$ /$1 [L,R]
#2 replace underscore with hypens
RewriteRule (.*)_(.*) $1-$2 [N,E=uscores:yes]
RewriteCond %{ENV:uscores} yes
RewriteRule ^(.+)$ /post/$1 [L,R]
重定向

  • /新闻/美食酒吧

  • /邮政/富吧
您可以使用以下规则:

RewriteEngine on

# redirect "/news/foo_bar" to "/foo_bar"    
RewriteRule ^news/(.+)$ /$1 [L,R]
#2 replace underscore with hypens
RewriteRule (.*)_(.*) $1-$2 [N,E=uscores:yes]
RewriteCond %{ENV:uscores} yes
RewriteRule ^(.+)$ /post/$1 [L,R]

非常感谢你回来-非常好。在这些规则的上下文中,从原始url中删除.html的最佳方法是什么?非常感谢您的回复-非常好。在这些规则的上下文中,从原始url中删除.html的最佳方法是什么?