Jump to content

Subdomains Non-Multi-Store Using Wildcard & Maybe Htaccess Needed


IeM

Recommended Posts

Hi,

I have to integrate an affiliate program application that uses subdomain links to Prestashop 1.5.

 

Multi-Store can not be used for a few reasons to do with other functionality.

 

There are other reasons to use the membership subdomains as well.

 

We need to use wildcard subdomains so this has been set up on the server and the subdomains do access the site, but the URL is rewritten to www.domain.com instead of sub.domain.com

 

I am guessing that the htaccess file would have to be modified.

 

Can anyone tell me how to modify Prestashop 1.5 to allow http://wildcard.domain.com to display in the URL.

 

Thanks.

Link to comment
Share on other sites

  • 2 years later...

I was asked the same question by another member trying to solve this same issue.

 

While I have not got a complete solution, this is what I answered him with:

 

I needed to use wildcard subdomains for my multi-store and I could not find any answers.

 

After spending about US$1500 for programmers that could not quite get it right I came up with my own hack that does the job with one downside, and that is the site will still always revert back to www.domain.com. However, in the mean time I grabbed the subdomain value.

 

Basically I inserted a script at the beginning of the index page that grabbed the value of the subdomain, stored it as a session or constant, and then reset the header as www.domain.com. I can then use that value in my scripts.

 

What prestashop does is when it gets a non www subdomain is reset the header to www.domain.com and the site reloads.

 

I am really looking forward to the day that Prestashop enables subdomains as there is a number of uses for them.

 

Hope this helps you and anyone with the same very frustrating issue.

Link to comment
Share on other sites

  • 8 months later...

I try and make working wildcard subdomains.

First of all you must make changes in apache server and add server alias, something like this in my version:

ServerName domain.ru
ServerAlias *.domain.ru

than you must modify generateHtaccess function in Tools.php to write right Rewrite Condition

^(.+\.)?'.$domain.'$ instead of the old version ^'.$domain.'$

now you can get subdomain name and make some overrides over Frontcontoller and Link and Dispatcher classes for the right recognition of controller and his actions for subdomains (changes depends on what you needed to get via subdomain). In my case I want to get the city name from subdomain and show different content for different cities. Something like paris.domain.ru or praha.domain.ru .

 

I hope it will help to understand the right way

Link to comment
Share on other sites

  • 1 month later...

Hi wagood

I have exactly the same need as you!

i tried to apply your code in Tools php but my site always redirect to the main domain.

The wildcard is well configured. I made a test on the same server with a simple php file outside my prestashop site and it works.

 

 

Do you have any idea?

 

Thanks in advance !

Link to comment
Share on other sites

Hi wagood

I have exactly the same need as you!

i tried to apply your code in Tools php but my site always redirect to the main domain.

The wildcard is well configured. I made a test on the same server with a simple php file outside my prestashop site and it works.

 

 

Do you have any idea?

 

Thanks in advance !

 

I was just first step. Now you have the subdomain as a variable in script and can handle it for future use. You must make some overrides over Frontcontoller, Link, Dispatcher classes. The changes depends on what you want to get via subdomain. I don't have universal solution.

Link to comment
Share on other sites

Thank you Wagood for your assistance

i am a bit confused about this condition if (Shop::isFeatureActive()) { in the rewrite condition.

It doesnt change anything if i modify the function or put anything, there is no impact on front-office.

Here is my code.

 

if (Shop::isFeatureActive()) {
     fwrite($write_fd, 'RewriteCond %{HTTP_HOST} ^(.+\.)?'.$domain.'$'."\n");
                }

 

My need is just to accept wildcard subdomain in prestashop.

Many thanks for your support

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...