RewriteRule中的正则表达式需要考虑是否要加上^(匹配字符串开头)
[例一]
RewriteRule /news/(/d+)/.html /news/.php/?id=$1 [N,L]
不仅匹配
http://localhost/news/1.html
也会匹配
http://localhost/test/news/1.html
因此应当加上^
RewriteRule ^/news/(/d+)/.html /news/.php/?id=$1 [N,L]
这样就不会匹配
http://localhost/test/news/1.html
[例二]
RewriteRule /blog/user/(.+)/.html$ /blog/user/blog_show.jsp?userid=$1 [PT]
不仅匹配
http;//localhost/blog/user/1.html
也匹配
http;//localhost/test/blog/user/1.html
因此应当加上^
RewriteRule ^/blog/user/(.+)/.html$ /blog/user/blog_show.jsp?userid=$1 [PT]
这样就不会匹配
http://localhost/test/news/1.html
[apache关键词]
apache
[rewrite模块关键词]
httxt2dbm
mod_rewrite
ornext
RewriteBase
RewriteCond
RewriteEngine
RewriteLog
RewriteLogLevel
RewriteMap
RewriteRule
[rewrite模块常见用途]
改变查询参数的设定位置
[rewrite模块标记]
RewriteLog, 设置重写引擎日志的文件名
RewriteRule, 设置重写规则
[rewrite模块常见问题]
RewriteRule中的正则表达式需要考虑是否要加上^(匹配字符串开头)