简体   繁体   English

RewriteRule无法在VPS中编译正则表达式

[英]RewriteRule cannot compile regular expression in VPS

My previous server working fine. 我以前的服务器工作正常。 Today I changed new server and getting RewriteRule cannot compile regular expression on my htaccess. 今天,我更换了新服务器,并且RewriteRule无法在htaccess上编译正则表达式。

How to fix this line 如何修复这条线

RewriteRule ^([a-zA-Z0-9_-\s\$\:\!\?\[\]\(\)\'\"]+)$ %{QUERY_STRING}?file=$1 [L]

This is rule which rewrite all page to index.php file. 这是将所有页面重写为index.php文件的规则。 I am using Apache 2.2.29. 我正在使用Apache 2.2.29。 Thank you ! 谢谢 !

Your regex indeed looks suspect, try this rule: 您的正则表达式确实看起来很可疑,请尝试以下规则:

RewriteRule ^([][\w\s$:!()'"-]+)/?$ ?file=$1 [L,QSA]
  • hyphen needs to be at first or last position in character class to avoid escaping. 连字符必须位于字符类的第一个或最后一个位置,以避免转义。
  • No need to do all that escaping inside a character class. 无需在角色类中进行所有转义操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM