Thursday, July 19, 2018

configuration - Can I use nested directives in .htaccess in Apache 2.4

I am trying to simulate the permalink structure of a previous version of my site using Redirect and RedirectMatch rules in my .htaccess file.



I have different rules that I would to apply to different paths from my old site. Some directories have no analogue and I want them to redirect to a single location. Some directories contain many items (thousands) at varying locations and I want them to redirect smartly to their correct new locations in the new site.



It seems that I could guard and group related items with a basic regex test on to prevent all the contained grouped redirects from being tested if they would never match. In this method, the resulting configuration looks logical and coherent and can be easily auto-generated:





# These rules aren't considered if the request wasn't for a subpath of categories/software.


# All old store pages now invalid, go to main store.
RedirectMatch 301 .* /software-store/


# Regexes for each category of software to group them logically.
# And so that 1,000s of redirects don't get considered on each page load.


# Loads and loads of redirect lines for pages with arbitrary rules to product pages.
Redirect 301 "/categories/software/item/foo" /software-store/games/foo
Redirect 301 "/categories/software/item/bar" /software-store/productivity/bar
Redirect 301 "/categories/software/item/baz" /software-store/misc/baz
# ...


# Loads and loads of redirect lines. It could also be grouped into subdirectories of dlc/ and so on.
# ...



# ...


For a huge catalogue, a few guarding regexes can prevent thousands of useless tests.



I'm using Apache 2.4, where the directive is available, but the above directives aren't having the effect I expect. The interior s are being ignored completely.



If I remove the enclosing and just have the innermost s present the rules work, so I don't believe that my syntax or my Redirect rules are at fault.




I suspect that the problem is that I can't nest s, although this seems like a very common thing to want to do. I can't see any reference to nesting, allowed or otherwise, in the documentation.
http://httpd.apache.org/docs/2.4/mod/core.html#if



Can I nest directives? And if so/if not so, can you point me to the section of the documentation that says why.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...