将URL中的下划线替换为斜杠并删除扩展名


Replace underscore with slash in the URL and cut the extension

我有一个文件,http://example.com/house_location.phtml。我需要调用URL字符串http://example.com/house/location(不带结束的斜杠),并且该URL必须执行house_location. php。

所以我需要将"_"替换为"/"并删除扩展名"。pthml"。

我的最后一次尝试是:

RewriteEngine On
RewriteCond %{THE_REQUEST} ' /+house_([^/]+)'.phtml
RewriteRule ^ /house/%1? [L,R]
RewriteRule ^house/([^/]+)$ /house_$1.phtml [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^'.]+)$ $1.phtml [NC,L]

但是它不起作用。我该怎么修理它?

重写规则应该是这样的

RewriteRule ^/?([a-z]+)/([a-z]+)$ $1_$2.phtml

(在手机上书写)