【问题标题】:install wordpress alongside angular在 Angular 旁边安装 wordpress
【发布时间】:2019-01-28 08:08:02
【问题描述】:

我有一个使用 apache 服务器运行的 Angular 项目。 apache 文档根是/var/www/angular/dist/my-project。在这个文件夹中,我创建了一个符号链接,它引用了我安装了 wordpress 的/var/www/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。但是这个 index.html 页面不会像我输入任何随机 url 时那样显示 404。

【问题讨论】:

    标签: angular wordpress apache .htaccess


    【解决方案1】:

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

    使用 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 也可以生成动态页面路由。

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

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

    【讨论】:

      猜你喜欢
      • 2014-08-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 2019-03-02
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多