How To Serve A Subdomain As A Subdirectory

Configure reverse proxies to present subdomain content through unified URL paths--boost SEO, simplify branding, and optimize infrastructure for AI and automation deployments.

Modern web architectures often require running different applications on separate servers while presenting a unified user experience. A common scenario involves hosting a blog, documentation site, or specialized AI tool on a subdomain while wanting users to access it through a subdirectory path. This approach delivers significant SEO benefits, simplifies domain management, and provides a more cohesive brand experience.

The technique that makes this possible is reverse proxy configuration. By setting up a reverse proxy at your main domain, you can transparently forward requests for specific URL paths to different backend servers, each handling its own subdomain.

Whether you're running WordPress on a separate server or deploying AI-powered automation tools, reverse proxy architecture gives you the flexibility to scale each service independently while maintaining a unified brand presence.

Key Benefits of Subdirectory Architecture

SEO Optimization

All link authority flows to a single domain rather than being split between main domain and subdomains.

Unified Brand Experience

Users perceive all content as part of a cohesive site rather than separate properties.

Simplified Analytics

All traffic appears under one domain, making tracking and reporting more straightforward.

Infrastructure Flexibility

Move backend services between servers without affecting user-facing URLs.

Resource Isolation

Run compute-intensive AI applications on dedicated servers while maintaining unified presentation.

Cost Efficiency

Shared reverse proxy reduces SSL certificate and infrastructure management overhead.

Understanding Reverse Proxies

How Reverse Proxies Work

A reverse proxy sits between clients and your backend servers, receiving incoming requests and forwarding them to the appropriate destination. The reverse proxy examines the URL path and routes requests to different backend servers based on your configuration. For example, when Nginx receives a request for example.com/blog, it can forward that request to a WordPress server running at blog.example.com, receive the response, and deliver it back to the user--all while the user's browser shows the clean example.com/blog URL.

According to Kinsta's reverse proxy fundamentals, this architecture allows you to maintain a single domain namespace while distributing traffic across multiple backend services. The reverse proxy handles SSL termination, request routing, and load balancing, creating a seamless experience for both users and search engines.

URL Subdirectory Architecture

The URL subdirectory architecture fundamentally changes how users and search engines perceive your site's structure. When content lives at example.com/blog/post-title instead of blog.example.com/post-title, link authority flows to your main domain, users perceive a unified site, and analytics become simpler.

As documented by Jeffrey Everhart, this approach is particularly valuable for SEO because search engines treat subdomains as separate properties. By serving all content through subdirectories, you consolidate link equity and domain authority.

For AI and automation deployments, this architecture allows you to run compute-intensive applications on dedicated servers while presenting them through your main domain. An AI chatbot or document processing service can live on a separate server but appear to users as example.com/ai.

Nginx Configuration for Subdomain-to-Subdirectory Proxying

Basic Nginx Reverse Proxy Setup

Nginx excels as a reverse proxy due to its efficient event-driven architecture and straightforward configuration syntax. The basic structure involves defining a server block that listens on your main domain and using location blocks to specify which paths get proxied where.

The critical elements are the proxy_set_header directives, which pass important information about the original request to the backend server. Without these headers, the backend application would not know the user's true IP address, would not recognize the original protocol, and might generate incorrect URLs.

Kinsta's proxy headers configuration guide emphasizes that proper header forwarding is essential for applications behind a reverse proxy to function correctly. For production web development projects, proper proxy configuration ensures seamless integration between backend services and the main domain.

Basic Nginx Reverse Proxy Configuration
1server {2 listen 80;3 server_name example.com www.example.com;4 5 location /blog {6 proxy_pass http://blog.example.com;7 proxy_http_version 1.1;8 proxy_cache_bypass $http_upgrade;9 10 # Proxy headers11 proxy_set_header Upgrade $http_upgrade;12 proxy_set_header Connection "upgrade";13 proxy_set_header Host $host;14 proxy_set_header X-Real-IP $remote_addr;15 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;16 proxy_set_header X-Forwarded-Proto $scheme;17 proxy_set_header X-Forwarded-Host $host;18 proxy_set_header X-Forwarded-Port $server_port;19 20 # Proxy timeouts21 proxy_connect_timeout 60s;22 proxy_send_timeout 60s;23 proxy_read_timeout 60s;24 }25}

Handling Static Assets and Application Paths

In many cases, especially with WordPress, a single proxy_pass directive for the main path is insufficient. Applications often have static assets, JavaScript files, and other resources stored in specific directories that also need proxying.

Jeffrey Everhart's configuration guide demonstrates that comprehensive proxy configurations require separate location blocks for each application path to ensure all resources route correctly.

Comprehensive Nginx Configuration with Asset Paths
1# Main blog location2location ^~ /blog {3 proxy_pass http://blog.example.com;4 proxy_set_header Host $host;5 proxy_set_header X-Real-IP $remote_addr;6 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;7 proxy_set_header X-Forwarded-Proto $scheme;8}9 10# Static assets11location ^~ /blog/wp-content {12 proxy_pass http://blog.example.com/wp-content;13}14 15location ^~ /blog/wp-includes {16 proxy_pass http://blog.example.com/wp-includes;17}18 19location ^~ /blog/wp-admin {20 proxy_pass http://blog.example.com/wp-admin;21}

Apache Reverse Proxy Configuration

Setting Up Apache as a Reverse Proxy

Apache HTTP Server provides robust reverse proxy capabilities through its mod_proxy and mod_proxy_http modules. The ProxyPass directive maps the local path to the remote URL, while ProxyPassReverse adjusts response headers so redirects work correctly with the subdirectory URL structure.

According to Kinsta's Apache proxy documentation, properly configuring these directives is essential for maintaining URL consistency across redirects and backend responses. Our cloud infrastructure services can help you implement and manage reverse proxy configurations for production environments.

Apache Reverse Proxy Configuration
1<VirtualHost *:80>2 ServerName example.com3 ServerAlias www.example.com4 5 # Enable proxying6 ProxyRequests Off7 <Proxy *>8 Require all granted9 </Proxy>10 11 # Proxy /blog to blog.example.com12 ProxyPass /blog http://blog.example.com13 ProxyPassReverse /blog http://blog.example.com14 15 # Pass headers through16 ProxyPreserveHost On17 RequestHeader set X-Forwarded-Host "example.com"18 RequestHeader set X-Forwarded-Proto "http"19</VirtualHost>

WordPress-Specific Implementation

Updating WordPress Site Addresses

When moving WordPress from a subdomain to a subdirectory, updating the site's URL configuration is critical. Navigate to Settings > General and update both the WordPress Address (URL) and Site Address (URL) fields.

Jeffrey Everhart's WordPress setup guide provides detailed procedures for ensuring WordPress generates correct URLs after the migration.

WordPress URL Configuration in wp-config.php
1// In wp-config.php, add before the line that says "That's all, stop editing!"2define('WP_HOME', 'http://example.com/blog');3define('WP_SITEURL', 'http://example.com/blog');4 5// Handle HTTPS behind proxy6if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {7 $_SERVER['HTTPS'] = 'on';8}

Database URL Updates

Beyond the site address settings, WordPress stores URLs throughout its database--in post content, post GUIDs, widget configurations, and metadata. A comprehensive database update is necessary to replace all references to the subdomain with the subdirectory path.

Using WP-CLI provides efficiency for larger sites:

wp search-replace 'http://blog.example.com' 'http://example.com/blog' --all-tables-with-prefix

Jeffrey Everhart's database migration procedures recommend using tools that handle serialized data correctly to avoid breaking WordPress functionality.

Restricting Direct Subdomain Access

Once the proxy is configured and WordPress is updated, prevent direct access to the subdomain from external traffic to preserve SEO value and prevent duplicate content issues. Configure the backend server to only accept connections from the reverse proxy.

Apache .htaccess to Restrict Direct Subdomain Access
1<IfModule mod_rewrite.c>2RewriteEngine On3RewriteBase /4 5# Block access unless from the proxy server IP6RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.100$7RewriteRule ^(.*)$ - [L,R=404]8</IfModule>

Practical Use Cases for AI and Automation

Deploying AI Services Behind a Subdirectory

AI and automation services often require dedicated computational resources--GPU access, additional RAM, or specialized dependencies. Running these services on separate servers while presenting them through your main domain provides appropriate resources for AI workloads and a unified brand experience.

Infrastructure architecture patterns demonstrate how this separation allows organizations to optimize each service independently while maintaining consistent branding for end users. Our AI and automation services help organizations implement sophisticated reverse proxy architectures for production deployments.

AI Service Proxy Configuration with Extended Timeouts
1location ^~ /assistant {2 proxy_pass https://ai.example.com;3 proxy_http_version 1.1;4 proxy_set_header Upgrade $http_upgrade;5 proxy_set_header Connection "upgrade";6 proxy_set_header Host $host;7 proxy_set_header X-Real-IP $remote_addr;8 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;9 proxy_set_header X-Forwarded-Proto $scheme;10 11 # Timeouts for long-running AI requests12 proxy_connect_timeout 300s;13 proxy_send_timeout 600s;14 proxy_read_timeout 600s;15}

Cost Optimization Through Shared Infrastructure

Running dedicated AI infrastructure is expensive, but the subdomain-to-subdirectory pattern enables cost optimization through shared reverse proxy infrastructure--only one server handles SSL termination and traffic routing. The unified domain structure simplifies certificate management with just one SSL certificate for the main domain.

For high-volume services, auto-scaling backend servers behind the proxy matches resources to actual usage while presenting a stable URL structure to users. Our cloud infrastructure services can help you design and implement scalable architectures that optimize costs while maintaining performance.

Common Challenges and Troubleshooting

Redirect Loops

Redirect loops typically occur when the backend application generates redirects pointing to the subdomain, but the proxy doesn't adjust these headers. Check that WordPress site URLs are correctly set to the subdirectory path and that ProxyPassReverse (Apache) or equivalent header adjustments (Nginx) are configured.

Jeffrey Everhart's troubleshooting guide addresses redirect loop prevention and resolution.

SSL and Mixed Content Issues

HTTPS enforcement creates additional complexity when proxying between domains. Handle SSL termination at the proxy level and ensure proper protocol forwarding through headers. The backend application must recognize that the original request was HTTPS even though it receives plain HTTP from the proxy.

Kinsta's SSL configuration best practices explain how to properly terminate SSL at the reverse proxy while maintaining secure communication with backends. Our web development team can help ensure proper SSL configuration across all your reverse proxy deployments.

Performance and Timeout Considerations

AI and automation services often have different performance characteristics than traditional web applications. Long-running requests require extended timeout configuration on the reverse proxy.

Kinsta's proxy timeout guidelines recommend configuring timeouts based on expected workload characteristics, with AI services often requiring significantly longer timeout values. For production deployments with complex infrastructure requirements, our cloud solutions experts can help optimize your proxy configuration for performance and reliability.

Frequently Asked Questions

Ready to Deploy Your AI Infrastructure?

We help businesses implement sophisticated reverse proxy architectures for AI and automation deployments. Get expert guidance on infrastructure optimization, security, and scalability for your specific use case.

Sources

  1. Kinsta: How To Set Up a Reverse Proxy - Comprehensive reverse proxy guide with Nginx and Apache configurations
  2. Jeffrey Everhart: WordPress NGINX Proxy Server Subdomain to Subdirectory - WordPress-specific implementation details and database update procedures
  3. Ryan Himmelwright: Nginx as a Reverse Proxy to Forward Sub-Domains - Practical setup guide with infrastructure architecture patterns