Www subdomain redirects to plain domain

Hi everyone!

I have a vanilla installation of VMin with just one primary nameserver. Anytime I visit www.mydomain.tlp, my webbrowser redirects me to mydomain.tlp …

I have tried creating a CNAME record for www that leads to my mydomain.tlp, and I have tried creating an A record for www that leads to my IP … both options redirect me to mydomain.tlp …

I tried asking my registrar’s support and I tried their solution to no avail.

The DNS zone for that domain has a record for the domain and one for the www FQDN. But I don’t think that matters because I think I am using my registrar’s nameservers by default. I only have my primary nameserver on my VMin install.

Any ideas? I feel stranded like a whale on a beach.

DNS changed might take up to 24 hours, did you take that into account?
Otherwise you might take a look at mod_rewrite with htaccess.

Chrome browser could be the culprit - versions of chrome after 76 strip the https and www from the URL. You can see the actual URL by double-clicking on the address bar of the browser.

Hi @calport! I use Firefox and I checked by clicking the address bar. Other websites are displayed with the www subdomain. @DrCarsonBeckett, I also took DNS timing into account.

My apache server has mod_rewrite activated … but I don’t know what to do with it. My virtual servers have a few .htaccess documents … but they contain only code related to WordPress. :man_shrugging:

It might cause a loop, if its not what I expect. Try to add this code into the .htaccess file:

RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Make sure, that there is only one line with RewriteEngine On inside the .htaccess file.

huh? - in same /...folder ? - might you find a problem. - you should have only one .htaccess file in folder you trying.

@unborn I think he meant it more like on his servers are a few of them.
Otherwise I dont think you can have multiple files with the same name. Still, I am interessted in that answer now too. Didnt thought about that statement like that. :smiley:

@unborn, @DrCarsonBeckett there are several documents in the servers, one per folder.

I am reading about Apache language and directives … I will test your code soon, when I am a bit more familiar with the language. Thanks for the hint.

That code should be placed on the top level folder or within the main directory of website you want to redirect.

Hi everyone!

I have tried the code before and after some code WordPress automatically writes to my .htacces file in the virtual servers’s public_html directory, and it breaks the site.

Here is the WordPress code:

# BEGIN WordPress
# The directives (lines) between BEGIN WordPress and END WordPress are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I have also tried

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^url\.tlp$
RewriteRule (.*) http://www.url.tlp/$1 [R=301,L]

but these also broke the site infront and after the WordPress bits.

I have tried taking the constant [L] out of the code so Apache, when placing it in front of the WordPress bit so it is not the last directive it reads … and then I got a 301 Error with a link that loops.

# Moved Permanently

The document has moved [here](looping link).

Additionally, a 301 Moved Permanently error was encountered while trying to use an ErrorDocument to handle the request.

This I also tried just using:

Redirect 301 http://url.tlp http://www.url.tlp

and the browser just displays the url with no www in front.

I am also trying to understand the language of Apache directives … but I have read the language is just called Apache? And I have found this chart

Special Symbols:

Symbol Meaning
^ Start of the string
$ End of the String
Or [a b] – a or b
[a-z] Any of the letter between a to z

  • One or more occurrence of previous letter
  • Zero or more occurrence of previous letter
    ? Zero or one occurrence of previous letter
Constants and their meaning:
Constant Meaning
NC No-case or case sensitive
L Last rule – stop processing further rules
R Temporary redirect to new URL
R=301 Permanent redirect to new URL
F Forbidden, send 403 header to the user
P Proxy – grab remote content in substitution section and return it
G Gone, no longer exists
S=x Skip next x rules
T=mime-type Force specified MIME type
E=var:value Set environment variable var to value
H=handler Set handler
PT Pass through – in case of URL’s with additional headers.
QSA Append query string from requested to substituted URL

That helps understanding some of your code @DrCarsonBeckett, but I have no idea what the % or the ! do or what [HTTP_HOST] might be … I am so lost. :man_shrugging:

I think it is very strange that the WordPress directives have to directives with the [L] constant.

Ok … I changed it through WordPress :man_facepalming:

Thats one way to go. Btw, from what I read, you misunderstood the code itself and placed parts lines which were seemingly active already.
Its possible that my code wasnt valid anymore, just checked older .htaccess files of mine for that (which werent in use anymore).
But glad you fixed it. :slight_smile:

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.