htmonitor

Docker Testing Environment for .htaccess

Quick Start

# Build and start the container
docker-compose up --build -d

# Run automated tests
./test-scripts/test-countries.sh

# Open testing interface in browser
open http://localhost:8080/geoip-mock.php

Whatโ€™s Included

๐Ÿณ Docker Environment

๐ŸŒ GeoIP Mocking Methods

Method 1: Query Parameters

curl http://localhost:8080/?country=DE
curl http://localhost:8080/?country=UK
curl http://localhost:8080/?country=US

Method 2: HTTP Headers

curl -H "X-Test-Country: DE" http://localhost:8080/
curl -H "X-Test-Country: UK" http://localhost:8080/
curl -H "X-Test-Country: US" http://localhost:8080/

Method 3: Web Interface

Visit http://localhost:8080/geoip-mock.php for interactive testing with country buttons.

๐Ÿค– Google Bot Testing

# Test Google Bot with different countries
curl -H "X-Test-Country: DE" -A "Googlebot/2.1" http://localhost:8080/
curl -H "X-Test-Country: UK" -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" http://localhost:8080/

# Test Google Bot without country (should not redirect)
curl -A "Googlebot/2.1" http://localhost:8080/

Supported Countries

Code Country Expected Redirect Flag
US United States No redirect ๐Ÿ‡บ๐Ÿ‡ธ
GB United Kingdom /uk/ ๐Ÿ‡ฌ๐Ÿ‡ง
DE Germany /de/ ๐Ÿ‡ฉ๐Ÿ‡ช
FR France /fr/ ๐Ÿ‡ซ๐Ÿ‡ท
LU Luxembourg /fr/ ๐Ÿ‡ฑ๐Ÿ‡บ
AU Australia /au/ ๐Ÿ‡ฆ๐Ÿ‡บ
AT Austria /at/ ๐Ÿ‡ฆ๐Ÿ‡น
CA Canada /ca/ ๐Ÿ‡จ๐Ÿ‡ฆ
IE Ireland /ie/ ๐Ÿ‡ฎ๐Ÿ‡ช
IT Italy /it/ ๐Ÿ‡ฎ๐Ÿ‡น
CH Switzerland /ch/ ๐Ÿ‡จ๐Ÿ‡ญ
LI Liechtenstein /ch/ ๐Ÿ‡ฑ๐Ÿ‡ฎ
ES Spain /es/ ๐Ÿ‡ช๐Ÿ‡ธ
Other Any other /uk/ (fallback) โ“

Testing Scenarios

โœ… Expected Behaviors

  1. US Users: Stay on main site (no redirect)
  2. Known Countries: Redirect to country-specific subdirectory
  3. Unknown Countries: Fallback to UK (/uk/)
  4. Google Bot: No redirect regardless of country
  5. WordPress Admin: No redirect (protected)
  6. SEO Files: No redirect (robots.txt, sitemap)

๐Ÿงช Test Commands

# Test different countries
curl -I -H "X-Test-Country: DE" http://localhost:8080/
curl -I -H "X-Test-Country: US" http://localhost:8080/
curl -I -H "X-Test-Country: JP" http://localhost:8080/  # Unknown country

# Test Google Bot exception
curl -I -A "Googlebot/2.1" http://localhost:8080/

# Test protected areas
curl -I -H "X-Test-Country: DE" http://localhost:8080/wp-admin/
curl -I -H "X-Test-Country: DE" http://localhost:8080/robots.txt

# Test with query parameters
curl -I "http://localhost:8080/?country=FR"
curl -I "http://localhost:8080/?country=AU"

Debugging

๐Ÿ“Š View Logs

# Real-time logs
docker-compose logs -f htaccess-tester

# Apache access logs (with country info)
docker-compose exec htaccess-tester tail -f /var/log/apache2/access.log

# Apache error logs
docker-compose exec htaccess-tester tail -f /var/log/apache2/error.log

๐Ÿ” Debug Headers

The server adds debug headers to help troubleshoot:

๐Ÿ› ๏ธ Interactive Shell

# Access container shell
docker-compose exec htaccess-tester bash

# Check .htaccess syntax
docker-compose exec htaccess-tester apache2ctl configtest

# View current .htaccess
docker-compose exec htaccess-tester cat /var/www/html/.htaccess

File Structure

๐Ÿ“ Docker Environment
โ”œโ”€โ”€ ๐Ÿณ Dockerfile - Apache + PHP setup
โ”œโ”€โ”€ โš™๏ธ docker-compose.yml - Service orchestration
โ”œโ”€โ”€ ๐ŸŒ apache-vhost.conf - Apache configuration with GeoIP mock
โ”œโ”€โ”€ ๐Ÿงช geoip-mock.php - Interactive testing interface
โ”œโ”€โ”€ ๐Ÿ“‹ test-scripts/
โ”‚   โ””โ”€โ”€ test-countries.sh - Automated test script
โ”œโ”€โ”€ ๐Ÿ“„ .htaccess - Your actual .htaccess file (mounted)
โ””โ”€โ”€ ๐Ÿ“Š logs/ - Apache logs (mounted volume)

Troubleshooting

Common Issues

  1. Port 8080 in use ```bash

    Change port in docker-compose.yml

    ports:

    • โ€œ8081:80โ€ # Use different port ```
  2. .htaccess not working
    # Check if file is mounted correctly
    docker-compose exec htaccess-tester ls -la /var/www/html/.htaccess
       
    # Restart container after .htaccess changes
    docker-compose restart htaccess-tester
    
  3. Redirects not working
    # Check Apache error logs
    docker-compose logs htaccess-tester
       
    # Verify mod_rewrite is enabled
    docker-compose exec htaccess-tester apache2ctl -M | grep rewrite
    

Testing Tips

  1. Use curl -I for headers only (faster testing)
  2. Check X-Debug-Country header to verify country detection
  3. Test both methods: query params and headers
  4. Use the web interface for visual testing
  5. Monitor logs in real-time during testing

Cleanup

# Stop and remove containers
docker-compose down

# Remove images (optional)
docker-compose down --rmi all

# Remove volumes (optional)
docker-compose down -v