如何使用.htaccess RewriteRule将下划线更改为连字符

时间:2018-08-30 17:03:20

标签: wordpress apache .htaccess mod-rewrite

当我尝试将其重定向到我的网站根目录时。

例如:

https://example.com/video_cat/a-respiratory/

我希望所有下划线都替换为-(连字符),但是当我尝试这样做时,我会重定向到https://example.com

这是我的.htaccess配置

 RewriteEngine On

 RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
 RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]

完成.htaccess文件:

#BEGIN CORS access to staging environments

   #start start's here
   Options +FollowSymLinks
   RewriteEngine on
  #RewriteRule ^([^_]*)_+(.*)$ /$1-$2-$3 [L,NC,R=302]

  RewriteBase / 
  RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
  RewriteRule 

0 个答案:

没有答案