# Apache redirect config

**URL:** <http://fluxxset.com/t/apache-redirect-config/631>\
**Category:** Linux\
**Created:** [March 10, 2025, 6:51pm UTC](http://fluxxset.com/t/apache-redirect-config/631 "2025-03-10T18:51:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeus](http://fluxxset.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@zeus](http://fluxxset.com/u/zeus)\
**Post date:** [March 10, 2025, 6:51pm UTC](http://fluxxset.com/t/apache-redirect-config/631/1 "2025-03-10T18:51:59Z")

</div>

I have issue configuring my apache server to redirect properly. Below is what my config look like:

```auto
<VirtualHost *:80>
    ServerName domain

    default config...
</VirtualHost>

<VirtualHost *:80>
    ServerName www.domain

    { in this www host, I'm forwarding the traffic to inner flask server }
    ProxyPreserveHost On
    ProxyPass / http://flask-server
    ProxyPassReverse / http://flask-server
</VirtualHost>

```

it works as expected when I havent installed https, since I used letsencrypt to get https, I have been battling with redirection error as the server enter infinite redirect loop. I have used .htaccess to write redirection config, it doesnt work. I have used this `RedirectMatch permanent ^/(.*)$ https://domain/$1` nothing change, still the improper redirect error.

---

<div class="post-metadata">

**Author:** ![fluxxset](http://fluxxset.com/user_avatar/fluxxset.com/fluxxset/32/20_2.png) [@fluxxset](http://fluxxset.com/u/fluxxset)\
**Post date:** [March 10, 2025, 7:02pm UTC](http://fluxxset.com/t/apache-redirect-config/631/2 "2025-03-10T19:02:15Z")

</div>

i am not quite familier with apache , why dont u try nginx its qite stright forword there .

---

<div class="post-metadata">

**Author:** ![fluxxset](http://fluxxset.com/user_avatar/fluxxset.com/fluxxset/32/20_2.png) [@fluxxset](http://fluxxset.com/u/fluxxset)\
**Post date:** [March 10, 2025, 7:05pm UTC](http://fluxxset.com/t/apache-redirect-config/631/3 "2025-03-10T19:05:01Z")

</div>

```auto
# Redirect HTTP to HTTPS
server {
    listen 80;
    server_name domain www.domain;

    # Redirect all HTTP requests to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS configuration
server {
    listen 443 ssl;
    server_name domain www.domain;

    # SSL settings for Nginx (Let’s Encrypt certificates)
    ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/domain/chain.pem;

    # Proxy settings for Flask (running HTTPS)
    location / {
        proxy_pass https://flask-server; # Use https since Flask is running over HTTPS
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Optional: Disable caching for dynamic requests
        proxy_cache_bypass $http_upgrade;

        # Add this line to ignore SSL certificate verification when proxying
        proxy_ssl_verify off;
    }
}

```

---

<div class="post-metadata">

**Author:** ![zeus](http://fluxxset.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@zeus](http://fluxxset.com/u/zeus)\
**Post date:** [March 10, 2025, 7:10pm UTC](http://fluxxset.com/t/apache-redirect-config/631/4 "2025-03-10T19:10:24Z")

</div>

Thanks boss. I’m not familiar with nginx, I will use this as instructed. Please, provide a course on nginx. It will help a lot before I go for my sysadmin course.
