Forum Moderators: phranque
RewriteEngine on
<Location "/">
RewriteRule ^ - [E=foo:bar]
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s/body/BODY/i"
</Location> <?php
echo <<<EOF
<html>
<head>
<title>Test</title>
</head>
<body>
<pre>
EOF;
print_r($_SERVER);
echo <<<EOF
</pre>
</body>
</html>
EOF;
?> I see that $_SERVER['foo'] equals "bar", so the configuration is working properly and <Location> is matching.But it’s not a rock-solid test, since it involves different modules.
Context:directory, .htaccessI wish they wouldn't say this and then turn right around and give all their examples using <Location>. Are we to understand that for present purposes they are interchangeable? Since the substitution involves case changing, did you try it without the "i"? (Yes, I know the flag applies to the pattern, but let’s eliminate all options.) Edit: Also try it with a bit of regular text, not an html directive.
[edited by: phranque at 8:24 am (utc) on Jul 8, 2024]
[edit reason] disable graphic smile faces [/edit]
AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html I knew you would be the first in lineWell, you never know when some wild out-of-left-field notion will lead to a solution.
Substitute "s|(<body.*?>)|<!-- test -->\n$1|iq"
The .*? bit seems perilous in the extreme. Does mod_substitute's RegEx engine do single-line or whole text? If the idea is to potentially include things like <body class = "classname"> (I used to have a fair number of these in a directory that used a small number of possible color schemes for the individual pages) I’d say <body[^>]*>instead. Will this affect the entire compression of the site, though?It seems as if it would only apply to that category of files that are being substituted, i.e. all html files. If the real substitution (as opposed to the ones shown here for testing and/or posting purposes) is only meant to happen in a few files, then the AddOutputFilter business, along with the Substitute rule, could instead go in a <Files> or <Directory> envelope, whatever is appropriate.
<script type="text/javascript">var infolinks_pid = foo;var infolinks_wsid = 0;</script><script type="text/javascript" src="//resources.infolinks.com/js/infolinks_main.js"></script><script id="hydro_config" type="text/javascript">window.Hydro_tagId = "foo";</script><script id="hydro_script" src="https://track.hydro.online/"></script></head> If the real substitution (as opposed to the ones shown here for testing and/or posting purposes) is only meant to happen in a few files...
But if this is a WP site, isn't everything php?