我在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" )
}
我搜索了所有互联网,但我没有发现任何相关信息。我不知道我是不是写好了正则表达式,或者我把它放在了错误的地方。
答案 0 :(得分:1)
请改为尝试:
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
答案 1 :(得分:1)
我有同样的问题。 解决了这个问题:
url.rewrite-if-not-file = ( "(?!\.\w+$)" => "/index.html" )
参考文献:https://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite#urlrewrite-repeat-if-not-file
答案 2 :(得分:0)