使用PHP删除.php扩展名 [英] Remove .php extension with PHP
本文介绍了使用PHP删除.php扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在这里使用一些帮助.我正在用它来修复我的URL,但是我不知道如何删除.php扩展名.该URL现在看起来像这样: http://mydomain.com/page.php /foo/123/bar/456
I could use some help here. I'm using this to fix my URL but I can't figure out how to remove the .php extension. The URL looks like this now: http://mydomain.com/page.php/foo/123/bar/456
function decode_URL_parameters() {
$path = @$_SERVER['PATH_INFO'];
$url_array=explode('/',$path);
array_shift($url_array);
while ($url_array) {
$_GET[$url_array[0]] = $url_array[1];
array_shift($url_array);
array_shift($url_array);
}
}
有什么想法吗?
/Tobias
推荐答案
如果通过Apache提供服务,则需要查看mod_rewrite
.
If you're serving via Apache, you'll want to look at mod_rewrite
.
使用mod_rewrite
,您可以修改URL如何映射到应用程序的实际端点.对于您的示例,您需要这样的东西:
Using mod_rewrite
, you can modify how URLs are mapped to your application's actual end-points. For your example, you'll want something like this:
RewriteEngine on
RewriteRule ^/?page/(.*)$ page.php/$1 [L]
此页面还有其他一些简单示例.
This page has some other simple examples.
这篇关于使用PHP删除.php扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文