Tips for debugging .htaccess rewrite rules

后端 未结 16 3140
萌比男神i
萌比男神i 2020-11-21 05:17

Many posters have problems debugging their RewriteRule and RewriteCond statements within their .htaccess files. Most of these are using a shar

16条回答
  •  逝去的感伤
    2020-11-21 05:35

    Set environment variables and use headers to receive them:

    You can create new environment variables with RewriteRule lines, as mentioned by OP:

    RewriteRule ^(.*) - [E=TEST0:%{DOCUMENT_ROOT}/blog/html_cache/$1.html]
    

    But if you can't get a server-side script to work, how can you then read this environment variable? One solution is to set a header:

    Header set TEST_FOOBAR "%{REDIRECT_TEST0}e"
    

    The value accepts format specifiers, including the %{NAME}e specifier for environment variables (don't forget the lowercase e). Sometimes, you'll need to add the REDIRECT_ prefix, but I haven't worked out when the prefix gets added and when it doesn't.

提交回复
热议问题