AJAX requests sent to wrong (with language code) URL

Popular automatic website translation tool

AJAX requests sent to wrong (with language code) URL

Postby atriaforever » Thu Sep 27, 2018 2:16 pm

I have successfully installed GTranslate on a WP multisite install hosted on https://trials.knowledgeplaces.com" rel="nofollow" target="_blank, configured as directory install.
I have also choosen "directory install" for GTranslate and everything works as expected, except for AJAX requests I send from functions in a child theme.
They all fail if I navigate on a translated version of the site.
For instance, I have a page at https://trials.knowledgeplaces.com/trai ... turopathie" rel="nofollow" target="_blank.
This page sends AJAX requests to https://trials.knowledgeplaces.com/trai ... n-ajax.php" rel="nofollow" target="_blank
As long as I stay with the default language, it works fine, all AJAX requests are correctly sent and processed.
If I switch to a language such as english, AJAX requests are sent to https://trials.knowledgeplaces.com/en/t ... n-ajax.php" rel="nofollow" target="_blank, and they all fail with a 404 error.
Please explain how to proceed so AJAX requests work with any language.
atriaforever
 
Posts: 2
Joined: Thu Sep 27, 2018 2:12 pm

Re: AJAX requests sent to wrong (with language code) URL

Postby Edvard » Thu Sep 27, 2018 2:49 pm

Hi,

It means that gtranslate rewrite rules are not correctly added into your .htaccess file.

Make sure to open GTranslate settings page, then hit save, it should display with red color which should be added into .htaccess file. If it doesn't display anything, make sure to open your .htaccess file and move gtranslate rewrite rules to the top of the file.

You can contact our Live chat for more help. https://gtranslate.io/#contact" rel="nofollow" target="_blank

Thanks! :)
Regards,

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Edvard
Site Admin
 
Posts: 4403
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia

Re: AJAX requests sent to wrong (with language code) URL

Postby atriaforever » Thu Sep 27, 2018 10:48 pm

I run this WP on a Win Server 2012 with IIS as web server, not Apache.
IIS uses its own format to manage rewrite rules.
I have logged in to my server and I have seen that your plugin has generated a .htaccess file which contains multiple rewrite rules.
They are all written using the Apache .htaccess format.
In IIS, there is a utility to import a .htaccess file and convert them to IIS rules.
I run the utility but I have an error message on the first rule (see attached screen copy).
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
All other rules have been converted successfully.
Despite the error on the first rule, everything seems to work fine now.
Thanks for pointing me in the right direction.
Last thing: what is the purpose of the first rule? Do I need it on IIS?
atriaforever
 
Posts: 2
Joined: Thu Sep 27, 2018 2:12 pm

Re: AJAX requests sent to wrong (with language code) URL

Postby Yana » Fri Sep 28, 2018 10:43 am

Hi,


For IIS web servers use web.config files rules for sub-directory URL structure.

IIS rules:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="gtranslate 1L" stopProcessing="true">
<match url="^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$" />
<action type="Rewrite" url="/{R:1}/{R:3}" />
</rule>
<rule name="gtranslate 2L" stopProcessing="true">
<match url="^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$" />
<action type="Rewrite" url="/wp-content/plugins/gtranslate/url_addon/gtranslate.php?glang={R:1}&amp;gurl={R:2}" appendQueryString="true" />
</rule>
<rule name="gtranslate 3L" stopProcessing="true">
<match url="^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)$" />
<action type="Rewrite" url="/{R:1}/" />
</rule>

<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>

</system.webServer>
</configuration>
Regards,

Yana Ghahramanyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Yana
 
Posts: 4547
Joined: Thu Jan 12, 2012 6:21 pm


  • Related Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: Google [Bot] and 0 guests