How do I replace an underscore with a dash using htaccess?

前端 未结 1 1545
深忆病人
深忆病人 2021-01-22 02:54

Okay here is my url:

http://example.com/home/process_login

I would like to replace the underscore with a dash.

So http://example.com/h

1条回答
  •  被撕碎了的回忆
    2021-01-22 03:56

    Use this code:

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    
    RewriteRule ^(home/)(.*)-(.*)$ $1$2_$3 [L,NC]
    

    UPDATE: Based on your comments below

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} !^/?(coremeasures/index\.php/|index\.php|home/|images/|robots\.txt)
    RewriteRule ^(.*)$ /coremeasures/index.php/$1 [L]
    RewriteRule ^(home/)(.*)-(.*)$ $1$2_$3 [L,NC]
    

    UPDATE 2: Based on your comments below

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    
    RewriteRule ^(?!(coremeasures/index\.php/|index\.php|home/|images/|robots\.txt))(.*)$ coremeasures/index.php/$1 [L]
    RewriteRule ^(home/)(.*)-(.*)$ $1$2_$3 [L,NC]
    

    0 讨论(0)
提交回复
热议问题