请ppended在请求URI字符串$ P $ [英] Keep the string prepended in request uri

查看:133
本文介绍了请ppended在请求URI字符串$ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个字preSS的网站有两个语言支持英语和丹麦语。

I am building a Wordpress website with two language support English and Danish.

我要保持语言code字符串连接英语和丹麦prepended在请求URI。

I want to keep the language code string en for English and da for Danish prepended in request uri.

我爱:(目前,这是为我工作)

Like: (Currently this is working for me)

http://example.com/da

如果我访问文章或网页,它应该是地图是这样的:(这不是工作,让404)

If i visit post or page, it should be map like this: (This is not working, getting 404)

http://example.com/da/post-name
http://example.com/da/page-name
http://example.com/da/post/is/too/long

我也尝试字preSS改写API

add_rewrite_rule() (重写规则目前,我有)

add_rewrite_rule() (Rewrite rules currently i have)

<?php
add_action('init', function () {    
    add_rewrite_rule(
        '^(da|en)/?', //Regex
        'index.php?lang=$matches[1]', //request to
        'top' //called earlier than wordpress rules
    );
});

和也 add_rewrite_tag() ,但我认为字preSS只是提供的 add_rewrite_endpoint (我不需要这在所有)。
我认为这可能只是有可能与htaccess的%{QUERY_STRING} 的条件? (不知道)

and also add_rewrite_tag(), but i think Wordpress just provide an add_rewrite_endpoint (and i don't need this at all).
I think it may only be possible with htaccess %{QUERY_STRING} conditions? (Don't know)

的.htaccess内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

编辑:
我使用 WP本地信息中心翻译上的管理员我只是用 __()键,但在头版 _e()。莫的.po 文件和它的工作完美。


I'm using WP Native Dashboard for translation on admin pages however on front i'm just using __() and _e() with .mo and .po files and its working perfectly.

P.S:
这个问题不是特定于Word preSS的网站,我也需要这样的帮助,在未来的定制基础的网站。如果你能提供给我的.htaccess规则/条件。

P.S:
This problem is not specific to Wordpress website, I also need this help with custom based websites in future. Provide me .htaccess rules/conditions if you can.

推荐答案

如果我是你,我会用插件,而不是从零实现。您可以使用插件多语言的wp网站。这个插件为您提供了三种类型的URL结构;

If I were you, I would use plugin instead of implementing from zero. You can use this plugin for multilingual wp site. This plugin provides you three types of url structure;

  1. ?LANG = EN
  2. / EN /富/
  3. en.yoursite.com
  1. ?lang=en
  2. /en/foo/
  3. en.yoursite.com

如果你想使用自定义网站,则可以使用以下重写规则;

If you want to use for custom site, you can use following rewrite rule;

RewriteEngine On
RewriteBase /
RewriteRule ^(en|da)/(.*)$ /$2?language=$1 [QSA,L]

我想,你正在使用语言参数语言

编辑:上有qTranslate插件的一些错误。这个错误可以解决的附加插件叫做 qTranslate弹头。不要忘了使用这个额外的插件,如果你面对URL模式问题

There is some bugs on qTranslate plugin. That bugs can be solvable with additional plugin called qTranslate Slug. Do not forget to use this additional plugin, if you faced url pattern problems

这篇关于请ppended在请求URI字符串$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆