首页 > 解决方案 > 在 Angular 旁边安装 wordpress

问题描述

我有一个使用 apache 服务器运行的 Angular 项目。apache 文档根目录是/var/www/angular/dist/my-project. 在这个文件夹中,我创建了一个符号链接,它引用了/var/www/wordpress我安装 wordpress 的目录。在“000-default.conf”文件中我有

RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(json|css|gif|ico|jpg|js|png|swf|txt|svg|woff|ttf|eot)$
#added this line to make the wordpress work
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule . /index.html [L]

但是上面的代码不起作用。我总是得到角度项目 index.html

但是,如果我去 domain.com/blog 它再次返回 index.html。但是如果我键入任何随机 url,这个 index.html 页面不会显示 404。

标签: angularwordpressapache.htaccess

解决方案


尽管这可能无法回答您的直接问题,但也许我可以提供替代解决方案。

使用 Xo for Angular,您可以将由 WordPress 提供支持的博客合并到您现有的 Angular 应用程序中,并将其作为集成应用程序提供服务。

https://wordpress.org/plugins/xo-for-angular/

Xo for Angular 可以帮助您编写重写,以通过 WordPress 加载 Angular 主题或直接为所有前端请求加载。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^xo-api/(.*)$ /index.php [NC,L]
    RewriteRule ^wp-json/(.*)$ /index.php [NC,L]
    RewriteRule ^/?$ /wp-content/themes/angular-xo-material/dist/index.html [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wp-content/themes/angular-xo-material/dist/index.html [L]
</IfModule>

文档(正在进行中):https ://angularxo.io/

插件github:https ://github.com/WarriorRocker/angular-xo-core

示例主题:https ://github.com/WarriorRocker/angular-xo-material

应该可以将现有的 Angular 应用程序复制到新主题,并让 Xo for Angular 插件加载并将前端请求定向到 Angular 索引。然后,您可以使用 Xo API 检索 WordPress 中的页面和帖子。如果您决定让 Xo 和 WordPress 控制,Xo for Angular 也可以生成动态页面路由。

完全披露我是上述插件和主题的作者。

如果您认为这对您有用,请告诉我,谢谢!


推荐阅读