Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Redirecting to new URL!

Status Resolved
Add-on / Version Publisher v1.1.5
Severity Critical
EE Version v2.7.2

Peter Lewis

Dec 09, 2013

Hi,

Similar problem to this ticket: https://boldminded.com/support/ticket/624 which indicates what I want to achieve. But it’s ending up redirecting to an incorrect URL as it’s ignored the subdomain.

Default language is en and Ideally I want to be able to access the site on URLs without specifying the prefix, so:
http://local.domain.dev/about is the same as http://local.domain.dev/en/about

http://local.domain.dev/en/about - displays English (correctly)
http://local.domain.dev/nl/about - displays Dutch (correctly)
http://local.domain.dev/about - redirects to http://domain.dev/nl/about (note the removal of the subdomain and the inclusion of the incorrect prefix)

http://local.domain.dev/nl/about - displays Dutch (correctly)
then
http://local.domain.dev/en/about - redirects to http://domain.dev/en/about (note the removal of the subdomain)

I’ve removed the .htaccess file and it still redirects, so it seems to be Publisher causing it.

Any ideas how to fix?

#1

BoldMinded (Brian)

What is your site_url value set to?

#2

Peter Lewis

http://local.domain.dev/

Other Settings…

Force default language - No Add URL prefix - Yes Force URL prefix - No

#3

BoldMinded (Brian)

Is there any public url I can see this happening at?

Add ?pubilsher_debug=yes to your URL and at the bottom of the site it should print a bunch of stuff, copy/paste that or take a screenshot of it and attach to the ticket please.

#4

Peter Lewis

Nope afraid not, it’s on my local and client server protected by firewall (dev.domain.com - so assume will have the same issue).

Added the query string and nothing happens…? Tried turning on debug too, still nothing. So bit of rummaging around…

In this example I’m going from: http://local.domain.dev/nl/about to: http://local.domain.dev/about

Publisher_session.php line 640: $url = ee()->publisher_helper_url->add_trailing_slash($url); $url has the value of: http://local.domain.dev/about

line 656: ee()->publisher_lib->prev_lang_id = $this->session_language_id; $this->session_language_id has the value 2 (Dutch, which is correct).

line 659: $current_url = $this->get_current_url(); $current_url has the value: http://local.domain.dev/about

Line 673 then balls it all up: $url = ee()->publisher_helper_url->set_prefix($url); $url is then http://domain.dev/nl/about

Publisher_helper_url.php set_prefix method calls get_site_index

ee()->config->_global_vars[‘root_url’] is incorrectly set

…Plot thickens!

EE Config file is set like so: $config[‘site_url’] = “http://${_SERVER[‘HTTP_HOST’]}/”; Which outputs correctly: http://local.domain.dev/

But on line 207 of Publisher_session.php: ee()->config->item(‘site_url’) = http://domain.dev/ on the fronted. Exactly the same place in your code output from within the Control Panel shows the domain correctly http://local.domain.dev/

Disabling Extensions and outputting site_url into the template results in the incorrect URL still.

Hard coding the site_url config to: $config[‘site_url’] = “http://local.domain.dev/”; Still results in it changing.

Any ideas…?

#5

BoldMinded (Brian)

root_url is only set with the value of site_url. What is index_page set to?

#6

Peter Lewis

Oh boy, that was painful. It’s a multi-site so the site_url was being overrode inside the index.php. Doh!

Right back to the other issue…

How do I set it so that English always works without the prefix and other languages require it?

Can it only be done via the language switcher and never direct URL changes?

#7

Peter Lewis

To clarify I follow this route of URLs…

http://local.domain.dev/en/about - English http://local.domain.dev/nl/about - Dutch http://local.domain.dev/about - Dutch http://local.domain.dev/en/about - Still Dutch! http://local.domain.dev - Forces English http://local.domain.dev/en/about - English http://local.domain.dev/about - English http://local.domain.dev/nl/about - Still English!

#8

Peter Lewis

Possibly I’m muddying the ticket and these are different issues I’m having, but they do seem related. Another simplified example of the issue below - it seems that it needs to refresh on the current language to register it’s that language…

http://local.domain.dev/en - Shows English http://local.domain.dev/nl - Incorrectly shows English Refresh http://local.domain.dev/nl - Shows Dutch http://local.domain.dev/en - Incorrectly shows Dutch Refresh http://local.domain.dev/en - Shows English

#9

BoldMinded (Brian)

Try this config setting

$config[‘publisher_hide_prefix_on_default_language’] = ‘y’;

I can see the issue in my sandbox by changing the url manually, but if you use the language switcher everything works fine.

#10

BoldMinded (Brian)

Peter, try this change: https://gist.github.com/litzinger/6187fa4b0e1cd2db1fca

#11

Peter Lewis

I’ve been trying a combination of both these changes (config and Publisher_session changes), most result in the language not changing at all, but this addition: $segments = ee()->uri->segments;

Resolves the refresh (caching) problem.

So… http://local.domain.dev/en - Shows English http://local.domain.dev/nl - Shows Dutch http://local.domain.dev/en - Shows English All good if using the prefix everytime.

$config[‘publisher_hide_prefix_on_default_language’] = ‘y’; Prevents any other language from working - does this rely on another setting to work?

So 2 issues remain: 1. Currently without the prefix, the language served is the last language visited. 2. Removing the default language prefix (as detailed in original ticket referenced #624) and preventing duplicate content SEO problems.

I’ll test some more in the meantime.

Many thanks,

Peter

#12

BoldMinded (Brian)

Can you send me an export of your exp_publisher_settings table? Or take a screenshot of it so I can see your settings?

#13

Peter Lewis

1 0 enabled yes boolean 2 1 force_default_language no boolean 3 1 force_default_language_cp no boolean 4 1 get_language_from_browser yes boolean 5 1 url_translations yes boolean 6 1 url_prefix yes boolean 7 1 force_prefix no boolean 8 1 disable_drafts no boolean 9 1 draft_status_color #ff9228 string 10 1 default_view_status open string 11 1 default_save_status open string 12 1 draft_previews no boolean 13 1 diff_driver publisher.diff string 14 1 diff_enabled no boolean 15 1 diff_enabled_cp no boolean 16 1 diff_style full string 17 1 sync_drafts yes boolean 18 1 detailed_translation_status yes boolean 19 1 persistent_matrix yes boolean 20 1 persistent_relationships no boolean 21 1 hide_flags yes boolean 22 1 phrase_prefix phrase: string 23 1 current_phrases_variable_name current_phrases string 24 1 channel_approvals [“”] json 25 1 phrase_approval yes boolean 26 1 category_approval yes boolean 27 1 roles {”editor”:[“”],”publisher”:[“6”]} json 28 1 can_change_language [“6”] json 29 1 approval {”label”:”Send for approval?”,”subject”:”Alan Rogers Website: {approval_type} submitted for approval”,”template”:”{member_name} ({member_email}) has submitted the entry "{title}" for Publishing on {date}.\n\n<a >View Entry<\/a>”,”deny_template”:”<b>{screen_name} ({email})<\/b> will be notified that this draft approval has been denied. Please provide a reason and requested changes.”,”to”:[“1”],”reply_to”:”“,”reply_name”:”“} json 30 1 ignored_channels [“”] json 31 1 ignored_fields [“”] json 32 1 ignored_field_types [“”] json 33 1 display_fallback yes boolean 34 1 replace_fallback no boolean

Plus in the EE config this is commented out: //$config[‘publisher_hide_prefix_on_default_language’] = “y”;

#14

Peter Lewis

Here’s where I’ve got to…

The session_language_id doesn’t seem to ever get changed, which leads to the same language being shown even though the prefix changed.

So I’ve explored tweaks to the code based on your gist code to try to uncover the solution in the vain hope it’ll uncover the cause. None of the settings have changed from the above (including “publisher_hide_prefix_on_default_language” still commented out).

Changes to set_properties function… Around line 333:

+     $segments = ee()->uri->segments;

        // Front-end requests require a bit more
        if ( !$this->session_language_id)

Around line 365:

}
        else
        {
            // See if the language code in the segment is in our language list.
            // Allows for manual changes of language segment and immediate content updates.
            $lang_id = isset($segments[1]) ? array_search($segments[1], $this->language_codes) : FALSE;

            if ($lang_id)
            {
                $this->session_language_id     = $lang_id;
                ee()->publisher_lib->lang_id   = $lang_id;
            }
                ee()->publisher_lib->lang_code = isset($this->language_codes[$this->session_language_id]) 
                                            ? $this->language_codes[$this->session_language_id] 
                                            : $this->default_language_code;
            $this->set('site_language', $this->session_language_id);

This now seems to mostly work correctly with regards to switching language via the URL. But if I’m on the Dutch site (nl) and remove the prefix completely, it redirects to include the prefix (which would be the preferred behaviour of the English albeit reversed - to prevent access on the prefix). If I’m on English it correctly allows access to the URL without the prefix, but both prefix and non-prefix are available, so bad for duplicate content penalties.

So could you either help clarify why my usage case (with unmodified code) doesn’t work, as surely this is required and valid usage of the add-on? Or can you give me pointers as to what code needs modifying to correctly: Redirect to non-prefix URL if “publisher_hide_prefix_on_default_language” = true and default_language_code = ee()->publisher_lib->lang_code Change the language code/ID to default if URL accessed without prefix (instead of redirecting to add last used prefix).

#15

BoldMinded (Brian)

What do your cookies and EE cookie settings look like? A couple times I’ve seen duplicate cookies created for whatever reason with different domain values, e.g.

www.site.com and .site.com

Which really messed up the language switching. In one case I remember the user had hard coded a cookie domain setting in EE and as soon as we removed it and let EE use the default values everything started working.

#16

Peter Lewis

No cookie domain specified. Both CP and User Session Types are Cookies. I’ve also changed the CP to Cookies & Session and no difference.

I’ve tried testing in another browser, clearing all cookies and cache.

I’ve commented out all my code additions, except this line:

$segments = ee()->uri->segments;

This seems to solve some of the problems and almost replicate where I was above bar the redirection for dutch:

/en doesn’t get redirected to just / (therefore both URLs accessible) If going from /nl to / it remains on the “/” but in Dutch (so both URLs accessible and no prefix defaulting to last used language).

Will try without the added line and tweaking the settings…

#17

BoldMinded (Brian)

You don’t have a channel with entry url_titles that match your language codes by chance do you?

#18

Peter Lewis

url title with prefix - nope.

$segments = ee()->uri->segments;

can’t be removed as it then stops the language from changing.

$config['publisher_hide_prefix_on_default_language'] = "y";

can’t be added as again that results in the same issue (language doesn’t change).

Oddly going from /nl to / now redirects back to /nl (albeit it shouldn’t redirect but show the English).

#19

BoldMinded (Brian)

Peter, I think this is getting to a point where I need to debug this hands on. Would it be possible for you to package up the site with the database and send it to me so I can set it up and debug locally?

#20

Peter Lewis

Jinx - was just typing exactly the same - I’m going to try and replicate on a public facing URL, so I can give you access and also see if it behaves the same.

I’ll generate a new ticket with the details in and also another issue regarding Field Pack or Playa issue and keep that issue separate. I’ll try and sort it out in the next few hours.

Thanks.

#21

Peter Lewis

Hi, any updates on this issue?

#22

BoldMinded (Brian)

No, I was waiting for you to test on another server and hopefully provide me FTP access to take a look. I’m still unable to replicate locally, so I need to see your environment.

#23

Peter Lewis

Hi, I gave it to you on this ticket and referenced in the comment: https://boldminded.com/support/ticket/721

😊

#24

BoldMinded (Brian)

I will try to look at this tonight.

#25

BoldMinded (Brian)

Peter, can this ticket be closed and we just use #721 from here on out?

#26

Peter Lewis

Hi, up to you? If it’s easier because of the log on details assigned to that ticket, then yep, that’s fine.

#27

BoldMinded (Brian)

to reproduce:

Currently in a fresh browser the following happens: http://domain.com/nl/about (shows Dutch - correct) http://domain.com/about (redirects to http://domain.com/nl/about - incorrect, should be English with no redirection) http://domain.com/en/about (shows English - incorrect, should redirect to URL without prefix) http://domain.com/about (redirects to http://domain.com/nl/about - incorrect should present English no URL change)

#28

BoldMinded (Brian)

I closed the other ticket before I realized the FTP info was in it, so its gone now. Can you re-add the FTP info to this ticket? Sorry :/

#29

Peter Lewis

Done. Thanks.

#30

BoldMinded (Brian)

I turned off the url translations setting because you didn’t have any translated template values. And I can’t edit your config.php file to add this to it:

$config[‘publisher_hide_prefix_on_default_language’] = ‘yes’;

I would also suggestion changing all your navigation links to use {site_url} instead of /, that way Publisher won’t have to do an additional redirect to add the language code.

href=”{site_url}campsites/walking-cycling”

#31

BoldMinded (Brian)

I also removed your cookie prefix setting because it was creating duplicate cookies.

#32

Peter Lewis

Done. I’ve set it to: “y” not “yes” 😉
if ($setting == ‘y’ AND ee()->publisher_lib->lang_id == ee()->publisher_lib->default_lang_id)

Now it doesn’t pick up the language at all. You should be able to change config settings via Deeploy Helper module.

“url translations” - not yet, but the intention is to use it later - but that’s fine to turn off for the time being.

{site_url} - thanks will do, basically haven’t progressed much further until this issue is resolved. I’ve been displaying at the top of the template to see how it’s interpreting the URL.

#33

BoldMinded (Brian)

Peter, going to go ahead and close this because I’m pretty sure 1.1.3 resolves the issue of redirection when hiding the default language segment. I too experienced the same issue on a client’s site I was working on and was able to fix it.

#34

Peter Lewis

Hi Brian, afraid not. Sorry for the delay, had shutdown over Christmas and this is the first chance I’ve had to pick this up again.

So there are 2 issues outstanding - default prefix can’t be hidden and redirection without prefix is incorrect.

/en/about - English site. /nl/about - Dutch site.

Fine and correct (ish).

From /nl/about type: /about (no prefix) and it redirects to /nl/about (incorrect, but not the point I’m trying to make…) From /en/about type: /about (no prefix) and it redirects to /nl/about - Incorrect as based on the rules above, English was the last language visited and English is the default, but it seems to be just redirecting to the last language in the list.

Soooo, could this redirect issue be just that without the language identifier, it’s getting the last language in the list, instead of looking at the default?

But, I’ve also got:

$config['publisher_hide_prefix_on_default_language'] = "y";

So the “en” shouldn’t even be appearing as a prefix.

If I try to access the homepage with no prefix, there’s no redirection but it will always deliver the dutch page.

:(

#35

BoldMinded (Brian)

Emailed you 1.1.5

#36

BoldMinded (Brian)

I think the FTP password provided is incorrect.

#37

Peter Lewis

Have reset and tested it - please try again.

#38

BoldMinded (Brian)

Peter, give it a shot now. I just uploaded a new version of Publisher and the test page is loading fine (it seems).

#39

Peter Lewis

Hi Brian, looking good - thank you. Just the final issue outstanding…

There’s an issue with going from /nl/ to no prefix (and retaining current session), as it will redirect to /nl/ and not redirect to English (en being default prefix - and should be used when no prefix shown). I appreciate that’s probably intended behaviour, but not ideal when it should be obvious via the URL where I’m going.

It still doesn’t redirect/prevent access to /en/, and due to the above I can’t do that via htaccess: RewriteRule ^en/(.*)$ /$1 [L,NC,R] If they come from /nl/ going to /en/ it will rewrite removing the /en/ then Publisher will rewrite again to add /nl/.

So basically if there’s no prefix, can it ignore the session and use the default prefix?

#40

BoldMinded (Brian)

Can you elaborate on your first paragraph some more? I’m going to /nl/about, loads Dutch, then switch to English, it loads English with no prefix. The language is properly set in the session in both cases.

I’ll take a look at forcefully removing the prefix in this instance.

“So basically if there’s no prefix, can it ignore the session and use the default prefix?” - Yes, I refactored everything to look for prefixes first, then set the session cookie, so if no prefix is present it will use the default language, regardless of what the cookie is currently set to.

#41

BoldMinded (Brian)

Peter, I made a couple of adjustments. Give the site a look now.

#42

Peter Lewis

Hi Brian,

/en/about now gets redirected/rewritten to /about (cool) But visit the homepage (no prefix or just /en/) and it gets a redirection error and never loads.

/about (entered manually in the URL) then visit /nl/about (manually) - all fine. From there, enter /about again in the URL manually and it redirects to /nl/about (showing Dutch) instead of no redirection and showing English.

Peter

#43

BoldMinded (Brian)

OK, I reverted my previous change so your site loads. I’ll revisit it tonight or tomorrow.

#44

Peter Lewis

The changes did correctly redirect the English though - so you couldn’t get to /en/ - which is good. So right place, just seems to go wonky when no URL (segments) exists and from /nl/ to no prefix, still picks up session.

The site is purely for your use, so you don’t have to revert anything - up to you.

#45

BoldMinded (Brian)

Ok, take a look now 😊 I made a change locally and forgot to update your site too.

#46

Peter Lewis

Nice - thank you. Alas it still doesn’t want to go from /nl/about to /about (manually changing the URL) which redirects back to /nl/about, but going from /nl/about to /en/about does correctly redirect to /about (showing English). I thought that wouldn’t be too much of an issue, but if you consider the Dutch homepage:

/nl

It would be quite logical to just remove the /nl manually in the browser URL and expect English, but this redirects back to /nl. So the only way to get to the English site is to use the language switcher (which sits in the footer) or to manually replace /nl with /en, which then correctly takes them to / (no prefix).

If that’s not possible to resolve (appreciate all the time you’ve already spent on this) then I can live with that - it’s solid in all the other previous issues so I’m happy.

Peter

#47

BoldMinded (Brian)

Try it now 😊

#48

Peter Lewis

Yay! Magic. All perfect now. Many thanks again for your support - very much appreciated.

Login to reply