How to create WordPress in a subdirectory of Next JS application
P粉006540600
P粉006540600 2023-08-29 14:53:13
0
1
499
<p>Dear community, Hello,</p> <p>My web application uses next JS under the domain name domain.com</p> <p>Now I want to create a wordpress blog (wordblog.com/community) under example.com/community</p> <p>Using Next JS Rewrites, I added this to my next configuration: </p> <pre class="brush:php;toolbar:false;">async rewrites() { return { fallback: [ { source: "/community/:path*", destination: `https://wordblog.com/community/:path*`, }, ], } },</pre> <p>In my WordPress installation folder. </p> <p>1- Add it to .htacces</p> <pre class="brush:php;toolbar:false;"><IfModule mod_headers.c> <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$"> Header set Access-Control-Allow-Origin "*" </FilesMatch> </IfModule></pre> <p>2-Add this to wp-config.php: </p> <pre class="brush:php;toolbar:false;">define('WP_SITEURL', 'https://wordblog.com/community'); define('WP_HOME', 'https://example.com/community'); define('COOKIE_DOMAIN', '.example.com');</pre> <p>3-Added this wp-content/themes/your-theme/functions.php</p> <pre class="brush:php;toolbar:false;">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); }</pre> <p>But when I visit domain.com/community, it redirects me to wordblog.com/community. </p> <p>In addition, some pages of wordblog.com/community are rendered under wordblog.com/community/pageX instead of domain.com/community/pageX</p>
P粉006540600
P粉006540600

reply all(1)
P粉154798196

You may be able to use the Alias ​​directive in your apache settings to resolve this issue: https://httpd.apache.org/docs/2.0/mod/mod_alias.html#alias

This means you have to remove the redirect in nextJS. Apache will know to serve /community from your WordPress installation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template