Forum Moderators: phranque
RewriteEngine on
RewriteRule ^a([a-f0-9]{12})\.jpg$ /images.php?content=$1 [L]
[edited by: engine at 9:46 am (utc) on Jan 31, 2022]
[edit reason] Please use example.com [/edit]
I can place it in the document rootWell, that’s a better idea anyway :) Especially when you're dealing with mod_rewrite, whose inheritance rules are not as straightforward as other mods.
it will actually match the url https://example.com/a123456789012.jpgOrdinarily, you would do this in the root by expressing the pattern as
AND the url https://example.com/image/a123456789012.jpg
^images/a([a-f0-9]{12})\.jpg According to the logs:Yup, that’s now mod_rewrite works in a directory context, whether in .htaccess or in a <Directory> section. But this log entry only makes sense if it’s applied to a RewriteRule that is, in fact, located in the /image/ directory. Did you forget to delete/comment-out the relevant part of the directory's htaccess before moving the rule to the root?
[perdir /home/XXXXX/public_html/image/] strip per-dir prefix: /home/XXXXX/public_html/image/a123456789012.jpg -> a123456789012.jpg
I am very confused as to what's changed on me.Unfortunately, only you are in a position to find out. Since this is about htaccess, I assume you are on shared hosting. Was there a recent Apache upgrade, or some other tweak? The directory-stripping seems particularly weird, if as you say it is applied to directories other than the one containing the htaccess file.
This has been working for years and suddenly stopped breaking content.
But this log entry only makes sense if it’s applied to a RewriteRule that is, in fact, located in the /image/ directory. Did you forget to delete/comment-out the relevant part of the directory's htaccess before moving the rule to the root?
defined "breaking" please.
what response did you get from requesting a so-named jpg file?
RewriteRule ^a([a-f0-9]{12})\.jpg$ /images.php?content=$1 [L] RewriteRule ^image/a([a-f0-9]{12})\.jpg$ /images.php?content=$1 [L] I get a 301 redirect to the webrootWh, wh, wh, wh, what now? Redirects don’t just come out of the clear blue sky. What rule is causing this to happen?
Wh, wh, wh, wh, what now? Redirects don’t just come out of the clear blue sky. What rule is causing this to happen?
Are there other RewriteRules in the same htaccess? Do those continue to work as intended?
In my personal experience, the only time I’ve met unexpected handling of directories in mod_rewrite is when a rule is inside an envelope such as <FilesMatch>--which may well be why Apache strongly discourages this approach. (I haven’t done this in a while, but did it years ago with image-specific rules.) And, even then, I don’t think the directories are stripped away; instead they are replaced by the whole physical filepath.
And, just to double-check: You don't have any mod_alias redirects (“Redirect” or “RedirectMatch”) do you?
I get a 301 redirect to the webroot, because it's no longer matching any rules with the folder in the url (in this case /image/*)
it bypasses the rule looking for /image/ECT , and moves on down the list. (and hits a WordPress redirect to index.php)
Something is not right here, because WP doesn’t do that. Instead, it internally rewrites everything to index.php
According to the logs:Yup, that’s now mod_rewrite works in a directory context, whether in .htaccess or in a <Directory> section. But this log entry only makes sense if it’s applied to a RewriteRule that is, in fact, located in the /image/ directory. Did you forget to delete/comment-out the relevant part of the directory's htaccess before moving the rule to the root?
[perdir /home/XXXXX/public_html/image/] strip per-dir prefix: /home/XXXXX/public_html/image/a123456789012.jpg -> a123456789012.jpg