Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] .htaccess News Manager + I18N setup
#1
Hello,
I finally got my custom url structure working but I need special rules for the News Manager.

My .htaccess looks like this
Code:
# News Manager
RewriteRule ^newspage/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^newspage/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^newspage/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^newspage/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]
# End News Manager

# To make custom permalinks work with the secondary language in the address only :) Permalink structure: %nondefaultlanguage%/%parent%/%slug%/
RewriteRule ^/?$ cs/ [R,L]   # optional
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(cs|en)/(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$3&lang=$1 [QSA,L]
RewriteRule ^(cs|en)/?$ index.php?lang=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?/)?([A-Za-z0-9_-]+)/?$ index.php?id=$2&lang=cs [QSA,L]

What it does is that if the site is currently in the Czech language (the default language), a page's URL is like this
Code:
http://mydomain.com/newspage
and like this
Code:
http://mydomain.com/en/newspage
in the secondary language (English).

The problems is that the News Manager's .htaccess line are only for the default language with the default URL structure without any /en/. So after clicking onto some of the news it works only if my site is currently in the default language, if it's in the secondary, I got page not found error from the NM.

What I need is some condition I could implement into my .htaccess to make the NM posts work for both addresses (with and without /en/ in the structure).

My thought is something like this
Code:
# News Manager

if ($language == 'cs') {
RewriteRule ^clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]
};
if ($language == 'en') {
RewriteRule ^en/clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^en/clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^en/clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^en/clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]
};

# end News Manager
I don't really understand how to implement these conditionals in there. My suggestion "surprisingly" doesn't work.

My current programming project is a java calculator, I'm not good at that, I'm even worse in PHP and I don't understand how .htaccess work at all. So sorry that I can't help myself with this.
I would really appreciate your help.

Thank you.

Tom


Edit://
I have just tried deleting both conditionals and just keeping both URL structures for Czech and English and it works a bit. What it does with the settings below is that after clicking onto a post on the News Manager page it switches the site to the secondary language, English, and then shows the article. Obviously it doesn't switch the language back after leaving the News manager article. If I change the order of the NM rewrite rules, nothing changes.
Code:
# News Manager nastaveni:

RewriteRule ^clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]

RewriteRule ^en/clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^en/clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^en/clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^en/clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]

# end News Manager
It would be perfect if clicking onto a post would not change the site's language. Can you help me, please? Smile


Edit2://
I have also tried some advice from the Wiki, which is...
Code:
url.rewrite-once = (
"/test/page/test123post/(.*)" => "/test/index.php?id=test123&post=$1",
"/test/page/(.*)" => "/test/index.php?id=$1"
)
... and edited it for my site
Code:
url.rewrite-once = (
"/demo/testTeeJay/plus/page/clanky/(.*)" => "/demo/testTeeJay/plus/index.php?id=test123&post=$1",
"/demo/testTeeJay/plus/page/(.*)" => "/demo/testTeeJay/plus/index.php?id=$1"
)
And then found it that it's only for tge Lighttpd which doesn't have to be on every server, that's not good. Furthermore, I didn't have a file to write it in... sad story.
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#2
I suppose it can be done in a better way (I don't know much about rewriterules), but after doing some tests, this works for me:

Code:
#...
# News Manager
# default language:
RewriteRule ^clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]
# English:
RewriteRule ^en/clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1&lang=en [L]
RewriteRule ^en/clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1&lang=en [L]
RewriteRule ^en/clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1&lang=en [L]
RewriteRule ^en/clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1&lang=en [L]
# end News Manager

# Permalink structure %nondefaultlanguage%/%parent%/%slug%/ with Czech (cs) as default language
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en)/(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$3&lang=$1 [QSA,L]
RewriteRule ^(en)/?$ index.php?lang=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$2&lang=cs [QSA,L]

# end of .htaccess file

News Manager's "Posted on ..." and "Go back to previous page" strings are always displayed in the default language, however. But links to posts work in both languages (without patching NM!)
Reply
#3
(2013-04-22, 05:05:28)Carlos Wrote: I suppose it can be done in a better way (I don't know much about rewriterules), but after doing some tests, this works for me:

Code:
#...
# News Manager
# default language:
RewriteRule ^clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1 [L]
RewriteRule ^clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1 [L]
RewriteRule ^clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1 [L]
RewriteRule ^clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1 [L]
# English:
RewriteRule ^en/clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1&lang=en [L]
RewriteRule ^en/clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1&lang=en [L]
RewriteRule ^en/clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1&lang=en [L]
RewriteRule ^en/clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1&lang=en [L]
# end News Manager

# Permalink structure %nondefaultlanguage%/%parent%/%slug%/ with Czech (cs) as default language
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en)/(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$3&lang=$1 [QSA,L]
RewriteRule ^(en)/?$ index.php?lang=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$2&lang=cs [QSA,L]

# end of .htaccess file

News Manager's "Posted on ..." and "Go back to previous page" strings are always displayed in the default language, however. But links to posts work in both languages (without patching NM!)
Thank you, that's nice that you set that up directly for my lang choice.

I tried your setup exactly as you proposed (I copied that) and there are still some errors you 1) didn't have, or, 2) failed to notice.

If the site is set to be in English, everything is ok. However, if it's in Czech, the title page switches me to English and can't be switched back to Czech until leaving the title page. Furthermore, the same happens with a post. When I click onto any of the posts, I'm switched to English and switching into Czech returns me to the page with the posts list and excerpts (clanky).

Of course I don't have the NM patched, don't you worry. I had better checked the functions.php once more and it's not applied, so it's correct.

Edit://
If I add

RewriteRule ^/?$ cs/ [R,L] # optional

in above the permalink structure setup in the .htaccess I get "Page not found" like from the NM.
This RewriteRule adds /cs/ to your title page URL and makes your site Czech (after visit with the root url) until you manually switch to English.
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#4
Did you change get_header by get_i18n_header, and get_navigation by get_i18n_navigation in your template?

My tests have been done with Spanish (es) as default language but I edited it for you :-)
BTW I've used GS 3.1.2. I'll try with 3.2
Reply
#5
(2013-04-22, 06:04:32)Carlos Wrote: Did you change get_header by get_i18n_header, and get_navigation by get_i18n_navigation in your template?

My tests have been done with Spanish (es) as default language but I edited it for you :-)
BTW I've used GS 3.1.2. I'll try with 3.2
I was using get_header, so now I changed to get_i18n_header but nothing changed. I'm using
Code:
<?php get_i18n_navigation(get_parent(0)==''?return_page_slug():get_parent(0),0,0); ?>
for my navigation. The submenu is much more complex, but I don't think it has anything to do with this.

I'm using 3.2.
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#6
Just upgraded my test site to 3.2.0 and it works ok.

Do you have set cs as default language in View All Pages (I18N) ?
Reply
#7
(2013-04-22, 06:18:55)Carlos Wrote: Just upgraded my test site to 3.2.0 and it works ok.

Do you have set cs as default language in View All Pages (I18N) ?
If you mean this, and I think you mean, then yes.
[Image: 10h3ino.jpg]

Btw after I started using get_i18n_header(); my homepage crashed even in English because I have a jquery slideshow there which is loaded via get_header only thanks to using FancyBox plugin and also gallery stopped working (clearly because of not loading jquery). Never mind, I can use I18N Gallery instead and load jquery manually with a link.

Edit:// Reuploading the site to a free hosting for you to see...
Edit2:// Look http://websimple.cz/demo/testTeeJay/plus/
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#8
I finally got it working this morning.

To prevent the site from switching from Czech to English after clicking onto a post, I had to add &lang=cs behind every "Czech" NM line of .htaccess.

It looks like this now.
Code:
# News Manager nastaveni:

# for Czech (default language - that's important, it's without /cs/ in the url)
RewriteRule ^clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1&lang=cs [L]
RewriteRule ^clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1&lang=cs [L]
RewriteRule ^clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1&lang=cs [L]
RewriteRule ^clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1&lang=cs [L]

# for English (secondary language)
RewriteRule ^en/clanky/tag/([^/.]+)/?$ index.php?id=clanky&tag=$1&lang=en [L]
RewriteRule ^en/clanky/post/([^/.]+)/?$ index.php?id=clanky&post=$1&lang=en [L]
RewriteRule ^en/clanky/page/([^/.]+)/?$ index.php?id=clanky&page=$1&lang=en [L]
RewriteRule ^en/clanky/archive/([^/.]+)/?$ index.php?id=clanky&archive=$1&lang=en [L]

# end News Manager

And to not get any error on the title page, I had to keep both (cs|en) in the end of the .htaccess. So it looks like this
Code:
# To make custom permalinks work with the secondary language in the address only :) Permalink structure: %nondefaultlanguage%/%parent%/%slug%/
RewriteRule ^/?$ cs/ [R,L]   # optional
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(cs|en)/(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$3&lang=$1 [QSA,L]
RewriteRule ^(cs|en)/?$ index.php?lang=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?/)?([A-Za-z0-9-]+)/?$ index.php?id=$2&lang=cs [QSA,L]

I don't really know why did it work for you the way you proposed it and not for me.
I'm using get_header(false) again, it's the same as the get_i18n_header except the cannonical link with "en" at the end and doesn't affect anything else.

I don't really know why does "&lang=cs" have to be in the .htaccess, it's already set up in the admin panel (see the picture above).

Never mind. Important is that your "&lang=en" and my "&lang=cs" in the NM lines helped me. That's all that was needed and now it works.

Thanks a lot Smile
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#9
(2013-04-22, 16:36:43)TeeJay Wrote: I finally got it working this morning.

To prevent the site from switching from Czech to English after clicking onto a post, I had to add &lang=cs behind every "Czech" NM line of .htaccess.

...

I don't really know why did it work for you the way you proposed it and not for me.
...

I don't really know why does "&lang=cs" have to be in the .htaccess, it's already set up in the admin panel (see the picture above).

The I18N plugin uses two approaches to determine the language. Either the language is included in the URL (lang=xx) or the language is determined from the user's browser's language settings.

Thus not specifying the language in the URL for your default language will have it fall back to using the browser settings, which might have "cs" first for one user and "en" first for another user.

The default language in the settings is used only, if the browser settings are used, but none of the languages in the browser match the site's languages.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#10
(2013-04-22, 16:49:43)mvlcek Wrote: The I18N plugin uses two approaches to determine the language. Either the language is included in the URL (lang=xx) or the language is determined from the user's browser's language settings.

Thus not specifying the language in the URL for your default language will have it fall back to using the browser settings, which might have "cs" first for one user and "en" first for another user.

The default language in the settings is used only, if the browser settings are used, but none of the languages in the browser match the site's languages.

I see. That's how it works.

Why it worked for Carlos is that he has a Spanish browser and the default language he use is also Spanish.

But I have an English browser and use Czech as a default language, so it switches my language only.

This is very good to know.
Thanks for the explanation Mvlcek.
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#11
When using a permalink structure containing I18N's %language% or %nondefaultlanguage% tokens, frontend NM links (posts, archives, etc) are rendered properly (thanks to mvlcek's plugin, which is really amazing). However, in NM's backend/admin the "View post" links are broken (not valid).

Here's a possible fix. Edit news_manager/inc/functions.php, find this:
Code:
$url = find_url($NMPAGEURL, $NMPARENTURL);

Just after that line, insert this:
Code:
if (basename($_SERVER['PHP_SELF']) != 'index.php') // back end only
    if (function_exists('find_i18n_url')) // I18N?
      $url = find_i18n_url($NMPAGEURL, $NMPARENTURL, return_i18n_default_language());

@TeeJay Please test. Works for me but I could have missed something. I'll include something like this for NM 2.4.0
Reply
#12
@ Carlos

Works perfectly, thanks for that Wink


Btw, I occured a little I18N breadcrumbs problem. The whole I18N navigation includes hyperlinks with links to the current page, so I needed also the navigation to NM posts be links. I did this, which works, but there's a little trouble that you can immediately see, I think.

Code:
<p class="breadcrumbs" >
  <a href="<?php echo find_url('index',null); ?>">
    <?php if ($language == 'cs') { ?>Úvod<?php } ?>
    <?php if ($language == 'en') { ?>Home<?php } ?>
  </a>
    <?php get_i18n_breadcrumbs(return_page_slug()); ?>
    <a href="#"><?php nm_post_title('&raquo; '); ?></a>    
</p>

With this, the "»" (the prefix &raquoWink is also underlined (is a part of the hyperlink. So it's finally consistent with an exception. If I put the "»" outside the function, it would be shown all the time, even if there's nothing behind it. It's embarrasing to have an arrow pointing to an empty space, isn't it? Smile

So I would like something
IF nm_post_title == NOT EMPTY STRING, THEN show "»" and next to it the hyperlink to nm_post_title. So the hyperlink would be only the post title without the separator "»".

Can you write such line for me, please? Thank you.
Tomáš Janeček - Multilingual personal website powered by GetSimple
» The little I did for GetSimple
Reply
#13
(2013-04-25, 19:06:01)TeeJay Wrote: @ Carlos

Works perfectly, thanks for that Wink

Thanks for testing.

As for your request, I'll answer in the News Manager thread.
Reply




Users browsing this thread: 1 Guest(s)