【问题标题】:lighttpd and AngularJS html5 modelighttpd 和 AngularJS html5 模式
【发布时间】:2016-09-08 01:09:33
【问题描述】:

我在 lighttpd 服务器中有一个 angularJS Web,但是当我刷新或执行直接链接时,html5 模式不起作用(错误 404)。我的本地服务器运行 Apache,.htaccess 中的重写表达式没有问题。 这是 Apache 代码:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  #Options +SymLinksIfOwnerMatch
  RewriteEngine On
  RewriteRule !\.\w+$ index.html [L]
</IfModule>

这是 lighttpd.conf 的内容

server.modules = (
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
        "mod_rewrite",
)

server.document-root        = "/var/www/html"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html$
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/htm$

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

$HTTP["host"] == "myweb.io" {
    server.document-root = "/var/www/html/"
    url.rewrite-once = ( "!\.\w+$" => "/index.html" )
}

我已经搜索了所有的互联网,但我没有找到任何关于此的信息。不知道是不是正则表达式写得不好,还是放错地方了。

【问题讨论】:

    标签: angularjs html rewrite lighttpd mode


    【解决方案1】:

    只需设置以下内容就可以了:(不需要 mod_rewrite)

    server.error-handler-404 = "/index.html"
    

    但是,请注意旧版本中的明显错误,如 docs 中所述。

    【讨论】:

      【解决方案2】:

      试试这个:

      url.rewrite-once = ( "(?!\.\w+$)" => "/index.html" )
      

      参考:http://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite

      或者,将测试放在条件块中

      $HTTP["url"] !~ "\.\w+$" {
          url.rewrite-once = ( ".*" => "/index.html" )
      }
      

      参考:http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题。 解决了:

        url.rewrite-if-not-file = ( "(?!\.\w+$)" => "/index.html" )
        

        参考:https://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite#urlrewrite-repeat-if-not-file

        【讨论】:

          猜你喜欢
          • 2014-08-04
          • 2015-05-03
          • 1970-01-01
          • 1970-01-01
          • 2014-10-03
          • 2014-02-16
          • 2014-10-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多