+ -
当前位置:首页 → 问答吧 → 一个URL rewrite的问题,快把我逼疯了~!!!!

一个URL rewrite的问题,快把我逼疯了~!!!!

时间:2010-01-19

来源:互联网

以下是在apache 下可以正常使用的 .htaccess的内容:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?_route_=$1

现在要在IIS下的 ISAPI_Rewrite version 1.3 build 16(主机提供商不想升级到3.0) 下使用。请问 httpd.ini 应该如何写?


[ISAPI_Rewrite]
=================以下代码可以用作参考=======================
<?php
class ControllerCommonSeoUrl extends Controller {
 public function index() {
  if (isset($this->request->get['_route_'])) {
   $parts = explode('/', $this->request->get['_route_']);
   
   foreach ($parts as $part) {
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
    
    if ($query->num_rows) {
     $url = explode('=', $query->row['query']);
     
     if ($url[0] == 'product_id') {
      $this->request->get['product_id'] = $url[1];
     }
     
     if ($url[0] == 'category_id') {
      if (!isset($this->request->get['path'])) {
       $this->request->get['path'] = $url[1];
      } else {
       $this->request->get['path'] .= '_' . $url[1];
      }
     } 
     
     if ($url[0] == 'manufacturer_id') {
      $this->request->get['manufacturer_id'] = $url[1];
     }
     
     if ($url[0] == 'information_id') {
      $this->request->get['information_id'] = $url[1];
     } 
    }
   }
   
   if (isset($this->request->get['product_id'])) {
    $this->request->get['route'] = 'product/product';
   } elseif (isset($this->request->get['path'])) {
    $this->request->get['route'] = 'product/category';
   } elseif (isset($this->request->get['manufacturer_id'])) {
    $this->request->get['route'] = 'product/manufacturer';
   } elseif (isset($this->request->get['information_id'])) {
    $this->request->get['route'] = 'information/information';
   }
   
   if (isset($this->request->get['route'])) {
    return $this->forward($this->request->get['route']);
   }
  }
 }
}
?>

作者: jkungfu   发布时间: 2010-01-19

帮顶

作者: yjhappy   发布时间: 2010-01-19