RewriteCond %{REQUEST_URI} !^/component.php$
RewriteRule /*.php /component.php?key=jack
访问:component.php get变量会没有jack,而访问除开component.php的其他页面就有有Jack变量了。
这个也可以:
RewriteCond %{REQUEST_URI} !^/component.php$
# RewriteRule /*.php /component.php?key=jack
RewriteRule ^(.+?)\.php$ /component.php?key=jack
# RewriteRule /*.php /component.php?key=jack
RewriteRule ^(.+?)\.php$ /component.php?key=jack
你可以把参数带上:
RewriteCond %{REQUEST_URI} !^/component.php$
# RewriteRule /*.php /component.php?key=jack
RewriteRule ^(.+?)\.php$ /component.php?key=$1
感谢:PHP高级编程组:我姓-->苏同学,呵呵!
备注:
<VirtualHost *:80>
ServerAdmin jackxiang@****.com
DocumentRoot /usr/local/***/htdocs/***.act_view
ServerName zzz.act.***.com
AddDefaultCharset UTF-8
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/component.php$
RewriteRule /*.php /component.php?key=jack
# RewriteRule ^(.+?)\.php$ component.php?key=jack
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^/c/([a-zA-Z0-9]*)/([a-zA-Z0-9]*)$ /component.php
RewriteRule ^/c/([a-zA-Z0-9]*)$ /component.php
RewriteRule ^/c/(\w*)/(\w*) /component.php
ErrorLog /tmp/apache_****_act.log
CustomLog /tmp/apache_****_act.clog common
<Directory />
Options Includes FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
ServerAdmin jackxiang@****.com
DocumentRoot /usr/local/***/htdocs/***.act_view
ServerName zzz.act.***.com
AddDefaultCharset UTF-8
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/component.php$
RewriteRule /*.php /component.php?key=jack
# RewriteRule ^(.+?)\.php$ component.php?key=jack
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^/c/([a-zA-Z0-9]*)/([a-zA-Z0-9]*)$ /component.php
RewriteRule ^/c/([a-zA-Z0-9]*)$ /component.php
RewriteRule ^/c/(\w*)/(\w*) /component.php
ErrorLog /tmp/apache_****_act.log
CustomLog /tmp/apache_****_act.clog common
<Directory />
Options Includes FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
RewriteRule /*.php /component.php?key=jack 可以,但是用:
RewriteRule ^(.+?)\.php$ /component.php?key=jack 后,没法访问:
domian.com/component/index.php/framemain 奇怪!!!
原来是少个斜杠,于是重新测试apache的urlrewrite正确的如下:
<VirtualHost *:80>
ServerAdmin jackxiang@***.com
DocumentRoot /usr/local/tads/htdocs/****.act_view
ServerName ****.act.**.com
AddDefaultCharset UTF-8
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/component.php$
RewriteRule ^(.+?)\.php$ /component.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^/c/([a-zA-Z0-9]*)/([a-zA-Z0-9]*)$ /component.php
RewriteRule ^/c/([a-zA-Z0-9]*)$ /component.php
RewriteRule ^/c/(\w*)/(\w*) /component.php
ErrorLog /tmp/apache_****_act.log
CustomLog /tmp/apache_****_act.clog common
<Directory />
Options Includes FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
参考:http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_rewrite.html
必须参看:http://www.jackxiang.com/post/3439/
后面Bond:
RewriteCond %{REQUEST_URI} !^.*(\.css|\.js|\.gif|\.png|\.jpg|\.jpeg)$ //#如果是这些后缀的文件,就直接访问文件,不进行Rewrite
RewriteCond %{REQUEST_FILENAME} !-f //如果文件存在,就直接访问文件,不进行下面的RewriteRule.(不是文件或文件不存在就执行重写)
RewriteEngine on
RewriteRule !\.(js|ico|txt|gif|jpg|png|css|html|xml)$ index.php
RewriteCond %{QUERY_STRING} ^(.+)$ 这个能解释一下吗?好几个,这个就是符合有query语句的情况。From:ianzhang(张文驰)
请教一下,下面的 %{REQUEST_FILENAME}、!-f、!-d、[L] 分别是什么意思呢?谢谢!
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
答案:
%{REQUEST_FILENAME}表示请求的文件名
!-f不是一个文件
!-d不是一个目录
[L] 相当于link
[R]相当与redirect
[NC]不区分大小写。
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3437/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2013-2-6 11:50
评论列表