Chinaunix
标题:
Rewrite RewriteCond无效的问题
[打印本页]
作者:
shopokey
时间:
2010-03-08 23:36
标题:
Rewrite RewriteCond无效的问题
在对网站进行页面静态化时,配置了apache Rewrite的配置文件,大致如下:
RewriteEngine On
RewriteBase /cycshop/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)-battery.html$ batteries\.php?keyword=$1&%{QUERY_STRING} [L]
RewriteRule ^(.*)--battery-p-(.*).html$ index\.php?main_page=product_info&batteries=$1&products_id=$2&%{QUERY_STRING} [L]
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
这个是相对路径,因为我的程序不是在根目录下,不过我这个问题已经解决了。
我说下正确的方法
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)-battery.html$ batteries\.php?keyword=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)--battery-p-(.*).html$ index\.php?main_page=product_info&batteries=$1&products_id=$2&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^battery-(.*).html$ tags.php?ky=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
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