URL重写-图像和流媒体

来源:互联网 发布:好看的网游小说知乎 编辑:程序博客网 时间:2024/05/17 06:13

1.在include中创建media文件夹,放入三张图片

2.修改.htaccess文件

RewriteEngine On
#RewriteRule ^mytest\.html$ /testphp/product.php?product_id=123
RewriteRule ^Products/C([0-9]+)/P([0-9]+)\.html$ /include/product.php?category_id=$1&product_id=$2 [L]


RewriteRule ^Products/.*-C([0-9]+)/.*-P([0-9]+)\.html$ /include/product.php?category_id=$1&product_id=$2 [L]


RewriteRule ^catalog.html$ /include/catalog.php [L]


RewriteRule ^cartoons.html$ /include/cartoons.php [L]


RewriteRule ^.*-M([0-9]+)\..*$ /include/media/$1 [L]


3.cartooms.php文件,代码:

<?php
require_once("url_factory.inc.php");
?>
<html>
<head>
<title>URL Rewriting Media Files</title>
</head>
<body>
<img src="<?php echo make_media_url(1, "lu1", "jpg"); ?>" alt="lu1" />
<img src="http://localhost/include/media/lu2.jpg" alt="lu2" />
<img src="http://localhost/include/media/lu3.jpg" alt="lu3" />
</body>
</html>


4.在url_factory.inc.php中添加函数

function make_media_url($id,$name,$extension)
{
$clean_name=_prepare_url_text ($name);
$url=SITE_DOMAIN . '/' . $clean_name . '.' . $extension;
return $url;
}


5.修改config.inc.php的SITE_DOMAIN

<?php
define ('SITE_DOMAIN','http://localhost/include/media');
?>


6.访问结果:


0 0