apache.htaccessmod-rewrite

Should I escape these characters with a backslash in .htaccess?


I have this in my .htaccess:

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

Will it be fine as above, or should it have escape characters? I know javascript often uses \ to escape characters. Like below:

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

I need it for these characters: - _ , . all four of them.


Solution

  • You can use this rule:

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