Tuesday, October 27, 2015

configuration - Apache config: Return 404 for single



Is it possible to let Apache automatically return a 404 page for a single URL using the Location tag?





# ???



Solutions without mod_rewrite or any other modules preferred.


Answer



The only solution "without any modules", is to not have the resource exist. If the location doesn't exist, then it Apache will return a 404.



Otherwise, you will need to use mod_alias or mod_rewrite. mod_alias is the simpler and more efficient solution:




Redirect 404 /your/url/path


You use this inside your vhost, there is no need to put it in a Location block.



You can also use the RedirectMatch directive if you don't want to match URLs below /your/url/path:



RedirectMatch 404 ^/your/url/path$



This and more can be read in the mod_alias documentation


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...