如何在 Next JS 應用程式的子目錄中建立 Wordpress
P粉006540600
P粉006540600 2023-08-29 14:53:13
0
1
395

親愛的社區,您好,

我的網頁應用程式在網域domain.com下使用next JS

現在我想在 example.com/community 下建立一個 wordpress 部落格 (wordblog.com/community)

使用 Next JS Rewrites,我將其新增至我的下一個配置:

async rewrites() { return { fallback: [ { source: "/community/:path*", destination: `https://wordblog.com/community/:path*`, }, ], } },

在我的 WordPress 安裝資料夾中。

1- 將其加到 .htacces

  Header set Access-Control-Allow-Origin "*"  

2-將此添加到 wp-config.php :

define('WP_SITEURL', 'https://wordblog.com/community'); define('WP_HOME', 'https://example.com/community'); define('COOKIE_DOMAIN', '.example.com');

3-新增了此 wp-content/themes/your-theme/functions.php

remove_filter('template_redirect','redirect_canonical'); add_filter('rest_url', 'serve_rest_url_on_wp_subdomain'); function serve_rest_url_on_wp_subdomain ($url) { return str_replace('https://example.com/community', 'https://wordblog.com/community', $url); }

但當我造訪domain.com/community時,它會將我重定向到wordblog.com/community。

此外,wordblog.com/community 的某些頁面在 wordblog.com/community/pageX 下呈現,而不是在 domain.com/community/pageX 下呈現

P粉006540600
P粉006540600

全部回覆 (1)
P粉154798196

您或許可以在 apache 設定中使用 Alias 指令來解決此問題:https://httpd.apache.org/docs/2.0/mod/mod_alias.html#alias

#這表示您必須刪除 nextJS 中的重定向。 Apache 會知道從您的 WordPress 安裝中提供服務 /community。

    最新下載
    更多>
    網站特效
    網站源碼
    網站素材
    前端模板
    關於我們 免責聲明 Sitemap
    PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!