Regex 重写URL扩展

Regex 重写URL扩展,regex,apache,mod-rewrite,Regex,Apache,Mod Rewrite,我想重写一个url,比如 http://www.example.com/keyword-city.php 到 有什么简单的解决办法吗 编辑: 我需要一个动态的解决方案。例如: http://www.example.com/keyword1-city.php http://www.example.com/keyword2-city.php http://www.example.com/keyword3-city.php 到 这很简单: $url = 'http://www.example.co

我想重写一个url,比如

http://www.example.com/keyword-city.php

有什么简单的解决办法吗

编辑: 我需要一个动态的解决方案。例如:

http://www.example.com/keyword1-city.php
http://www.example.com/keyword2-city.php
http://www.example.com/keyword3-city.php

这很简单:

$url = 'http://www.example.com/keyword-city.php';
echo str_replace('.php', '/', $url);

在项目中添加.htaccess文件在此文件中添加以下代码:

RewriteEngine on
RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /.php

OP需要一个mod rewrite的解决方案,而不是PHP。谢谢你的回答。有没有一种方法可以用变量来实现这一点?我得到了大约200个带有“keyword city.php”、“keyword1 city.php”模式的文件,我想将所有文件重写为“/keyword city/all文件,您想将其重写为文件/keyword city/如果其他文件像“keyword-city1.php”,现在您可以不带扩展名重写,但像“keyword city”一样重写所有文件很复杂“我真的不明白你的评论。是否无法用text-text.php模式替换所有页面上的“.php”到“/”?
$url = 'http://www.example.com/keyword-city.php';
echo str_replace('.php', '/', $url);
RewriteEngine on
RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /.php