【发布时间】:2012-12-04 12:27:48
【问题描述】:
这不需要太多解释,很简单,以下是如何工作的:
RewriteRule ^errors/browser/?$ /_errors/browser.php?error=browser [NC,QSA,L]
这不起作用:
RewriteRule ^error/browser/?$ /_errors/browser.php?error=browser [NC,QSA,L]
上面两个sn-ps的唯一区别,就是去掉了error字尾的字母s
我不明白为什么在单词error 上添加s 会突然使这段代码工作。我能想到的唯一解释是error是保留字?是这样吗?
如果是这种情况,那么如何使用 .htaccess 文件匹配和重写单词 error?
更新
这是我的整个.htaccess 文件:
# Define the default document
DirectoryIndex index.php
# Turn on the rewrite engine
RewriteEngine On
# Compress all HTML, Javascript, CSS, XML... files
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Set the error page rewrites
RewriteRule ^errors/browser/?$ /_errors/browser.php?error=browser [NC,QSA,L]
# Set the general first level rewrites
RewriteRule ^([a-z-]+)\/?$ $1.php? [NC,QSA,L]
RewriteRule ^([a-z-]+)\/([a-z-0-9]+)\/?$ $1.php?id=$2& [NC,QSA,L]
【问题讨论】:
-
检查您的 HSP 是否有 mod_security 或 Suhosin。
-
@ÁlvaroG.Vicario 我都没有启用 :-)
-
您的 .htaccess 文件中还有其他规则吗?
-
@w3d 是的,将发布整个文件,请稍等 :-)
-
某些发行版会为错误文档创建
Aliases...您似乎受到了影响。在全局/VirtualHostapache 配置中查找ErrorDocument或Alias行(apache.conf、httpd.conf、conf.d/*.conf、sites-enabled/*等之一)
标签: php regex apache .htaccess