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

若如初见. 提交于 2019-12-20 03:08:45

问题


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/home/process-login will go to the above url, but it will still SAY process-login in the URL bar.

Hopefully this makes sense. The only solutions I've found have been redirects, and I don't want a redirect. I want it to read as I have outlined.


回答1:


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]


来源:https://stackoverflow.com/questions/8823228/how-do-i-replace-an-underscore-with-a-dash-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!