htaccess 正则表达式下划线和空格不起作用
RewriteRule ^([A-Za-z0-9'"%ãõáéíóúâêîôûàÁÃÕÁÉÍÓÚÂÊÎÔÛÀ\/\.\-]*)$ public_html/$1 [NC]
我在这里使用这个正则表达式,它工作得很好,但是如果我举个例子:
RewriteRule ^([A-Za-z0-9 _'"%ãõáéíóúâêîôûàÁÃÕÁÉÍÓÚÂÊÎÔÛÀ\/\.\-]*)$ public_html/$1 [NC]
这里不起作用。由于空格和下划线,我想在正则表达式中包含空格和下划线,但它根本不起作用。我必须添加一些特别的东西吗?
这也不起作用:
RewriteRule ^(.*)$ public_html/$1 [NC]
我希望能够输入任何内容并在 public_html 文件夹中打开。
例如,我输入:www.mysite.com/site_1.php 然后它打开: www.mysite.com/public_html/site_1.php
这个 .htaccess 表达式正在使用 Apache 2.2.17 在 HostGator 服务器中进行测试 我也在我的本地主机 Apache 2.2.17 中进行了测试,并且发生了同样的情况。
添加 _ 和空格或 .* 时给出的错误是这样的:
内部服务器错误
服务器遇到内部错误或配置错误, 无法完成您的请求。
请联系服务器管理员admin@localhost并告知 错误发生时的信息,以及您可能做过的任何事情 这可能导致了错误。
有关此错误的更多信息可能会在服务器错误中提供 日志。
提前谢谢你们了。
RewriteRule ^([A-Za-z0-9'"%ãõáéíóúâêîôûàÁÃÕÁÉÍÓÚÂÊÎÔÛÀ\/\.\-]*)$ public_html/$1 [NC]
I'm using this Regex up here and it works just fine, but if I put for example:
RewriteRule ^([A-Za-z0-9 _'"%ãõáéíóúâêîôûàÁÃÕÁÉÍÓÚÂÊÎÔÛÀ\/\.\-]*)$ public_html/$1 [NC]
This up here doesn't work. because of the Space and underline, I want to include spaces and underline in the regexp, but it doesn't work at all. do I have to add something special to it ?
And this also doesn't work:
RewriteRule ^(.*)$ public_html/$1 [NC]
I want to be able to type anything and open in the public_html folder.
Ex, I type: www.mysite.com/site_1.php
then it opens: www.mysite.com/public_html/site_1.php
This .htaccess expression is being tested in the HostGator servers using Apache 2.2.17
and I also tested in my localhost Apache 2.2.17 as well, and same happens.
The Error given when adding the _ and space or .* is this:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.Please contact the server administrator, admin@localhost and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.More information about this error may be available in the server error
log.
Thank you guys in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 regular-expressions.info:
除了上述字符之外,您不应该转义字符集中的字符。这里的简单技巧是确保将连字符保留在字符类的最末尾。这将连字符标识为文字。
为了避免“连续循环”,您可以在匹配规则之前包含此条件:
另外,如果您只是想匹配您也谈到的所有内容,我通常会执行如下操作。请注意,
%{QUERY_STRING}
用于传递任何 GET 变量。如果您不打算使用常规 GET 变量,则可以将其删除。我希望这些信息对您有所帮助。
From regular-expressions.info:
You shouldn't be escaping characters within the character set other than the ones mentioned above. The simple trick here is to make sure you keep the hyphen at the VERY END of your character class. This identifies the hyphen as a literal.
To avoid a "continuous loop" you could include this condition before your match rule:
Also, if you simply want to match everything like you also talked about, I usually do something like below. Note, the
%{QUERY_STRING}
is there to pass on any GET vars. You can remove that if you don't plan to use regular GET vars.I hope this information helps you out.