.htaccess using escape quotes

扶醉桌前 提交于 2020-01-05 12:11:44

问题


I have this .htaccess:

RewriteRule ^(aa.bbb|aaa,bbb|aaa-bbb|aaa_bbb||)/(.*)$ /index.html [L,NC]

Will it be fine as above or should it be with espae quotes. I know in javascript is often \ in use. Like below:

RewriteRule ^(aa\.bbb|aaa,bbb|aaa-bbb|aaa_bbb)/(.*)$ /index.html [L,NC]

I need it for - _ , . all four of them. Do I need \ or some other sign in .htaccess and what is it.


回答1:


  • From your rules only dot needs to be escaped (since that is special regex character)
  • Two || should be removed otherwise that can match empty string
  • You can use character class to greatly reduce your regex
  • Inside character class none of these character need to be escaped.

You can use this rule:

RewriteRule ^(aa[.,_-]bbb)/(.*)$ /index.html [L,NC]


来源:https://stackoverflow.com/questions/21734474/htaccess-using-escape-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!