Mobile app version of vmapp.org
Login or Join
Courtney195

: Why does apache redirect to www without RewriteRule So I have a webserver running on Apache, with a few virtual hosts. I want to default to https and hence I have a rewrite rule. <VirtualHost

@Courtney195

Posted in: #Apache2 #Htaccess #ModRewrite #Redirects #UrlRewriting

So I have a webserver running on Apache, with a few virtual hosts. I want to default to https and hence I have a rewrite rule.

<VirtualHost *:80>
ServerName example.com
ServerAlias example.com example.com RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) %{HTTP_HOST}/ [NC,R,L]
</VirtualHost>


The interesting thing is that, I always see multiple 301 happening. ie example.com/something -> example.com/something -> www.example.com/something

I thought it might be the ServerAlias that is causing the issue, so I split the conf to 2 separate rules

<VirtualHost *:80>
ServerName example.com
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) %{HTTP_HOST}/ [NC,R,L]
</VirtualHost>

<VirtualHost *:80>
ServerName example.com RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) %{HTTP_HOST}/ [NC,R,L]
</VirtualHost>


Still getting the same result. I don't have any rules anywhere to redirect to www, user enters example.com and without www, and I'm confused where does the second redirect come from.
I also don't have any .htaccess rules to perform redirects. What am I doing wrong here ?

Edit : Problem identified as a wordpress plugin doing the redirect. Thanks for hints from community.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Courtney195

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

From the redirect, it looks like this could be happening in the VirtualHost container for port 443.

Failing that, the redirect could be happening in the website code itself. (Which appears to be the case here - a WordPress plugin).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme