# Base (Site) URL problem when sending email to segment

**URL:** <https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448>\
**Category:** Product Support\
**Tags:** mautic-4\
**Created:** [March 21, 2023, 5:56pm UTC](https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448 "2023-03-21T17:56:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyl087](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jyl087](https://forum.mautic.org/u/jyl087)\
**Post date:** [March 21, 2023, 5:56pm UTC](https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448/1 "2023-03-21T17:56:23Z")

</div>

**Apologies: I edited this post because I partially fixed my original problem, but I still have one remaining issue with the unsubscribe\_text. Please see update in the reply below. Thank you!**

**Your software**  
My Mautic version is:4.4.7  
My PHP version is:7.4.30  
My Database type and version is: mariadb-10.3.35

**Your problem**  
My problem is:  
Hi all: new to Mautic, and just trying to get through initial setup and testing. I have Mautic running on a RHEL (Rocky 8) server on a private network behind a public Nginx reverse proxy.

On my private network, I can access the Mautic dashboard like this:

```auto
http://192.168.1.100/ma/s/dashboard

```

My Nginx reverse proxy and global Site URL setting is configured like:

```auto
https://www.example.com/ma/index.php

```

This seems to work fairly well; for example, on the public side, I can visit `https://www.example.com/ma/page/preview/1` and all seems good. **However,** if I add an image to the landing page, the link on the page looks like this:

```auto
https://www.example.com/ma/index.php/media/images/logo.png

```

and the backend (Mautic) webserver does a 301 redirect to:

```auto
http://192.168.1.100/ma/media/images/logo.png

```

In other words, it seems that if I’m calling for the “index.php” file, it rewrites the URL to the wrong BASE URL, not the one set up in the Mautic General Settings. I took a look at the `.htaccess` file and found that if I edit the RewriteRule on line 37, replacing the `%{ENV:BASE}` with `https://www.example.com/ma`, the problem is fixed. So, basically wondering if there’s some other setting that I need to update on the Mautic dashboard to fix this the correct way?

The second issue that I’m seeing is somewhat related. I sent a test campaign to see if the `{unsubscribe_url}` is set correctly to show my Contact Preference Page. Again, I’m seeing the wrong base URL in the unsubscribe\_url: I’m seeing this in the email: `http://192.168.1.100/ma/email/unsubscribe....` instead of `https://www.example.com/ma/...`.

Steps I’ve tried to fix the problem:  
Manually edited `.htaccess` file to fix the image loading problem: a hack, but seems to work.  
Not sure how to fix the unsubscribe\_url problem.

Thanks in advance for your help!

* * *

UPDATE: I think I may have fixed the problem regarding the Nginx proxy.

On my nginx proxy, I added the following to my config:

```auto
proxy_set_header Host $host;

```

This ensures that the original host (www.example) is sent to the backend (Mautic) server, which seems like it fixed the issue with the `.htaccess` file.

---

<div class="post-metadata">

**Author:** ![jyl087](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jyl087](https://forum.mautic.org/u/jyl087)\
**Post date:** [March 21, 2023, 6:08pm UTC](https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448/2 "2023-03-21T18:08:18Z")

</div>

UPDATE: I’m not sure what I did, but the subscribe\_url problem seems to have gone away. However, still wondering why when an URL containing `index.php` shows up, it redirects to the wrong base URL, unless I hack the `.htaccess` file.

UPDATE2: Er… maybe I spoke too soon. Not sure, but maybe the problem didn’t go away.

**UPDATE3** : There still seems to be a problem, perhaps during cron processing or somehow when an email is sent to a segment. When I view a preview of an email, for example like this:

```auto
http://192.168.1.100/ma/email/preview/3

```

The links inside the email look correct, for example unsubscribe looks like this: `https://www.example.com/ma/email/unsubscribe/xxxx`. Also, if I send a one-off email using the [Send Example] button, the resulting email has the correct links!

However, if I tell mautic to send out the real email to my test contact, once I get my email on [gmail.com](http://gmail.com), it reverts back to this form for unsubscribe:  
`http://192.168.1.100/ma/email/unsubscribe/xxx`

Very frustrating! Could there be something that’s cached? What else could be causing an actual email that’s sent to the test segment to behave differently from the preview?

Thanks!

---

<div class="post-metadata">

**Author:** ![jyl087](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jyl087](https://forum.mautic.org/u/jyl087)\
**Post date:** [March 22, 2023, 5:15pm UTC](https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448/4 "2023-03-22T17:15:05Z")

</div>

I think I found a bug in Mautic; at least a way to avoid this issue. As I described above, I set up Mautic on a back end server that gets reverse-proxyed and SSL’d to the public via Nginx.

In my tests, I found that when I log in to Mautic via its private IP like this: `http://192.168.1.100/ma/s/...` and I create an email, it uses the wrong base url for all the links in the email. I.e., it seems to ignore the system configuration base URL setting and goes for whatever I logged into Mautic with. This seems like a bug to me.

When I log in to Mautic through my reverse-proxy, `https://www.examnple.com/ma/s/...`, then It composes emails with the right base URL. This is unfortunate because I was hoping to completely block the admin interface from the general public.

I’d be interested in hearing from more experienced users whether I’ve missed some setting somewhere or whether this is indeed a bug.

Thanks!

---

<div class="post-metadata">

**Author:** ![ekke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ekke/32/296_2.png) [@ekke](https://forum.mautic.org/u/ekke)\
**Post date:** [April 5, 2023, 2:22pm UTC](https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448/5 "2023-04-05T14:22:36Z")

</div>

I think this is a known issue and will be fixed in 4.4.8

See this PR: [Fix segment mails not using site\_url [backport to 4.x] by nick-vanpraet · Pull Request #11920 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/11920)

🙂

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [April 6, 2023, 8:06am UTC](https://forum.mautic.org/t/base-site-url-problem-when-sending-email-to-segment/27448/6 "2023-04-06T08:06:25Z")

</div>

I wonder if it also affects the multi domain plugin…
