我加盟Sjoerd这个词,但有很多方法可以像你想要的那样重写你的url!
Apache和(IIS太)支持网址,就像这样:http://example.com/index.php/my-rewritten-url_62
function URISegment($segment)
{
$uri_array = explode('/',$_SERVER['REQUEST_URI']);
$uri_count = count($uri_array);
$returning_uri = array();
for($i = 0;$i<$uri_count;$i++)
{
if(empty($uri_array[$i]) || $uri_array[$i] == "index.php")
unset($uri_array[$i]);
else
array_push($returning_uri,$uri_array[$i]);
}
if($segment < count($returning_uri))
return $returning_uri[$segment];
else
return false;
}
这工作,但您需要定义基础URL过了,这需要在的开始被称为文件,并在每个图像,脚本等实现调用。
function BaseURL()
{
if(isset($_SERVER['HTTP_HOST']))
{
$base = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$base .= '://'. $_SERVER['HTTP_HOST'];
$base .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
else
{
$base = 'http://localhost/';
}
return $base;
}
在此之后,你可以使用,而不是这样的:
// http://example.com/?MyKey=Some-data
$MyKey = $_GET['MyKey']; //which is the first item
echo $MyKey;
// results: Some-data
此:
// http://example.com/?MyKey=Some-data
$MyKey = URISegment(0);
echo $MyKey;
// results: Some-data
你必须通过每一个相同的结果。
PS:
我喜欢这个解决办法,因为我需要他们喜欢我可以混合使用的URL类型:
example.com/index.php/index/evaled-article?some=db-stored&code=snipplet
当然,你可以重写你的URL像FRKT说:)
当然,如果你想隐藏index.php
你需要使用mod_rewrite,因为没有办法
如何进行POST时,到达评论部分的方式只是一个hyperl墨水? – John 2010-06-22 08:32:38
@约翰:你不能。 – 2010-06-22 08:54:25