{"id":3417,"date":"2019-01-20T14:55:07","date_gmt":"2019-01-20T09:25:07","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=3417"},"modified":"2026-10-06T09:57:50","modified_gmt":"2026-10-06T04:27:50","slug":"apache-rules-for-wildcard-api-end-points","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/apache-rules-for-wildcard-api-end-points\/","title":{"rendered":"Apache Rules for wildcard API end points"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\" id=\"mce_1\"><strong><strong>Post Dat<\/strong>e:<\/strong> January 23, 2018<br><strong>Last Updated:<\/strong> October 06, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When hosting applications that expose multiple API versions or dynamic API paths, configuring Apache manually for each endpoint can become difficult to maintain. A more efficient approach is to use wildcard proxy rules that automatically forward all API requests to the backend service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we&#8217;ll explain how to configure Apache VirtualHost rules to handle multiple API endpoints using a single configuration. This approach simplifies management and ensures that future API versions work without requiring additional Apache updates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example API Endpoints<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following API endpoints should all be routed to the same backend service:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>https:\/\/example.com\/api\/V1<\/li>\n\n\n\n<li>https:\/\/example.com\/api\/V2<\/li>\n\n\n\n<li>https:\/\/example.com\/api\/V3<\/li>\n\n\n\n<li>https:\/\/example.com\/api\/V1\/users<\/li>\n\n\n\n<li>https:\/\/example.com\/api\/V1\/api\/products<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of creating separate rules for each endpoint, Apache can use a wildcard pattern to handle them automatically.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Apache Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Update the VirtualHost configuration for your domain and add the following directives:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ProxyPreserveHost On\n\nProxyPassMatch \"^\/api(.*)$\" \"http:\/\/localhost:9000\/api$1\"\nProxyPassReverse \"\/api\" \"http:\/\/localhost:9000\/api\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration Explanation<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Directive<\/th><th>Description<\/th><\/tr><tr><td>ProxyPreserveHost On<\/td><td>Preserves the original Host header when forwarding requests.<\/td><\/tr><tr><td>ProxyPassMatch<\/td><td>Uses a regular expression to match all requests beginning with <code>\/api<\/code>.<\/td><\/tr><tr><td>ProxyPassReverse<\/td><td>Rewrites backend response headers so clients receive the correct URLs.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How It Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When a request reaches Apache, the proxy rule captures everything after <code>\/api<\/code> and forwards it to the backend application running on port <code>9000<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Request Flow<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-scaled.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"866\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-1024x866.png\" alt=\"\" class=\"wp-image-12120\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-1024x866.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-300x254.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-768x649.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-1536x1299.png 1536w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/apache_proxypassmatch_request_flow-2048x1732.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of Using Wildcard API Rules<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No need to create separate proxy rules for every API version.<\/li>\n\n\n\n<li>Easier maintenance and management.<\/li>\n\n\n\n<li>Supports future API endpoints automatically.<\/li>\n\n\n\n<li>Reduces Apache configuration complexity.<\/li>\n\n\n\n<li>Simplifies application scaling and versioning.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Testing the Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After updating the Apache configuration, verify the syntax and reload Apache:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apachectl configtest\nsystemctl reload apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can then test the endpoint:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl https:\/\/pheonixsolutions.com\/api\/V1<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected result:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Request successfully forwarded to backend service.<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using Apache wildcard proxy rules is an efficient way to manage multiple API versions and dynamic endpoints. By leveraging <code>ProxyPassMatch<\/code>, you can route all API requests through a single configuration, reduce administrative overhead, and ensure that new API endpoints are automatically supported without additional Apache updates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions (FAQ)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Why should I use ProxyPassMatch instead of multiple ProxyPass rules?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ProxyPassMatch<\/code> allows Apache to use regular expressions and handle multiple API paths with a single configuration, reducing maintenance effort.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Will future API versions work automatically?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Any endpoint matching <code>\/api\/*<\/code> will be forwarded to the backend without requiring additional Apache configuration changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Do I need to restart Apache after making changes?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After modifying the configuration, run a configuration test and reload Apache:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apachectl configtest\nsystemctl reload apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A full restart is generally not required unless Apache modules have been changed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-install-apache-superset-on-ubuntu-via-docker-compose\/\">How to Install Apache Superset on Ubuntu via Docker Compose<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-configure-apache-with-php-fpm-handler-in-ubuntu-20-04\/\">How to Configure Apache with PHP-FPM handler in ubuntu 20.04<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Have a technology challenge or looking for the right solution for your business? Our team can help you with <strong>cloud, DevOps, development, infrastructure, design, and more<\/strong>. Feel free to reach out to our experts <a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: January 23, 2018Last Updated: October 06, 2026 Introduction When hosting applications that expose multiple API versions or dynamic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[278,540,541],"class_list":["post-3417","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-apache","tag-apache-rules","tag-wildcard-api-end-points","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-T7","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=3417"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3417\/revisions"}],"predecessor-version":[{"id":12122,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3417\/revisions\/12122"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}