Jump to content

How to stop subdomain to be redirected to main domain?


bytesource
 Share

Recommended Posts

Hi,

The content of the website I am working on needs to be available in different languages.

I thought about using different subdomains for each language, like es.example.com, de.example.com.

With the help of static translations and multi-language fields it should be easy to switch the language content using this code snippet:

if($config->httpHost == 'es.example.com') {
    $user->language = $languages->get("spanish");
}

To test this approach on a live server I added a subdomain temp.example.com and had it point to the root folder of my current website. The problem is that when I type in temp.example com/some_page I get redirected to www.example.com/some_page.

Of course, this redirection will not work well with search engines, so I would like to ask if there is a way to stop the redirection subdomains.

Additional information:

  • The website I added the subdomain to is not a ProcessWire installation but is running on an old version of ModX.
  • The hosting provider is Hosteurope

Cheers,

Stefan
 

Link to comment
Share on other sites

Looks like a .htaccess issue.

Maybe there is a rule in your .htaccess that forces all subdomains to the www. version?

Might want to add an exception for each subdomain?

https://github.com/ryancramerdesign/ProcessWire/blob/master/htaccess.txt#L89

That is the line (and below) for the redirect of subdomains, my best guess you have a similair line like that in your MODx .htaccess

  • Like 1
Link to comment
Share on other sites

@ Pete

You are right, using ProcessWire on the server would make thinks easier to debug. Unfortunately, my site is far from ready, so I don't want to replace it with the current site at this moment. The site I am working on is just my business site, and I don't have any other sites to play with.

@ MichaMicha

 

Maybe there is a rule in your .htaccess that forces all subdomains to the www. version?

Might want to add an exception for each subdomain?

That was exactly the problem. Before, the rewrite rule in my .htacces file looked as follows:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.sovonex\.de [NC]

RewriteRule (.*) http://www.sovonex.de/$1 [R=301,L]

After commenting out these three lines, typing subdomain.domain.com does not redirect to www.domain.com anymore.

However, clicking on any internal link on the page still redirects to www.domain.com/some_page.

I attached the current htaccess file, as I could not find anything that would explain this behaviour.

Maybe someone using subdomains could post their relevant rewrite rules here.

Cheers,

Stefan

modx_htaccess.txt

Link to comment
Share on other sites

However, clicking on any internal link on the page still redirects to www.domain.com/some_page.

I took a look at your htaccess, and it appears to me that all the stuff that would matter here has been commented out. So I don't think that's the problem. Can you tell if the links that you click on actually have the full hostname in them? View the source or inspect the link and see if it includes the hostname. Ideally you'd want the link to be like "/path/to/page/" and not "http://domain.com/path/to/page/". ProcessWire itself never uses hostnames in its URLs for this reason, unless you manually put them in or you use the $page->httpUrl rather than $page->url. 

If you find that's not the problem, I would try it from another browser. Browsers can be pretty stubborn about letting go of hostname related 301s. 

Link to comment
Share on other sites

All internal links are relative links, but I just realized that I had a <base> tag in the header specifiying the default URL. After commenting this line out, typing subdomain.domain/some_page did not redirect to the main domain anymore. 

Thanks a lot for pointing me in the right direction!

Cheers,

Stefan

  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...