Chinaunix

标题: Rewrite RewriteCond无效的问题 [打印本页]

作者: shopokey    时间: 2010-03-08 23:36
标题: Rewrite RewriteCond无效的问题
在对网站进行页面静态化时,配置了apache Rewrite的配置文件,大致如下:

  1. RewriteEngine On
  2. RewriteBase /cycshop/
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteCond %{REQUEST_FILENAME} !-f


  5. RewriteRule ^(.*)-battery.html$ batteries\.php?keyword=$1&%{QUERY_STRING} [L]
  6. RewriteRule ^(.*)--battery-p-(.*).html$ index\.php?main_page=product_info&batteries=$1&products_id=$2&%{QUERY_STRING} [L]
  7. RewriteRule ^battery-(.*).html$ tags.php?ky=$1&%{QUERY_STRING} [L]
复制代码
访问如下 http://test.com/70--battery-p-111.html
正常来说如果有这个静态文件存在的话后面的rewrite是不应该再解析的,然而事实上却每次都会执行rewrite. 并不会真正调用存在的html文件,有人知道这个是怎么回事吗?
作者: HonestQiao    时间: 2010-03-10 13:17
RewriteBase /cycshop/这个是干嘛的?
作者: shopokey    时间: 2010-03-11 09:21
回复 2# HonestQiao

这个是相对路径,因为我的程序不是在根目录下,不过我这个问题已经解决了。
我说下正确的方法
  1. RewriteEngine On
  2. RewriteBase /
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteCond %{REQUEST_FILENAME} !-f

  5. RewriteRule ^(.*)-battery.html$ batteries\.php?keyword=$1&%{QUERY_STRING} [L]
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteCond %{REQUEST_FILENAME} !-f
  8. RewriteRule ^(.*)--battery-p-(.*).html$ index\.php?main_page=product_info&batteries=$1&products_id=$2&%{QUERY_STRING} [L]
  9. RewriteCond %{REQUEST_FILENAME} !-d
  10. RewriteCond %{REQUEST_FILENAME} !-f
  11. RewriteRule ^battery-(.*).html$ tags.php?ky=$1&%{QUERY_STRING} [L]

  12. RewriteCond %{REQUEST_FILENAME} !-d
  13. RewriteCond %{REQUEST_FILENAME} !-f

  14. RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=category&batteries=$1&products_id=$2&%{QUERY_STRING} [L]
复制代码
这样写以后,比如说我访问http://www.shopokey.com/laptop-battery-c-134.html的时候,如果网站目录下存在laptop-battery-c-134.html文件的话就不会再去执行RewriteRule 了
我也是无意中尝试出来的,希望碰到类似问题的朋友有所帮助!
作者: qiyu15555    时间: 2010-03-14 15:32
记号




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2