Angularjs 配置Apache将URL重写为根目录中的index.html
我的AngularJS应用程序使用html5模式创建漂亮的URL。本地环境中的URL正常工作,但直接在浏览器中键入完整URL会导致我的测试服务器(在Heroku上设置)响应404个“未找到”错误 示例:Angularjs 配置Apache将URL重写为根目录中的index.html,angularjs,apache,heroku,configuration,server,Angularjs,Apache,Heroku,Configuration,Server,我的AngularJS应用程序使用html5模式创建漂亮的URL。本地环境中的URL正常工作,但直接在浏览器中键入完整URL会导致我的测试服务器(在Heroku上设置)响应404个“未找到”错误 示例: DocumentRoot "C:/Sites/myApplication" <Directory "C:/Sites/myApplication"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverr
DocumentRoot "C:/Sites/myApplication"
<Directory "C:/Sites/myApplication">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
web: vendor/bin/heroku-php-apache2 -C apache_app.conf
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
1)直接在浏览器中键入“localhost/log_in”或“localhost”将显示登录页面
2)在我的浏览器中直接键入“localhost/fkjdlfdsaf”或以“localhost/”开头的任何其他url将导致登录页面
3)直接在浏览器中键入“myapplication.herokuapp.com”(测试环境)也会导致登录页面
4)但是,键入“myapplication.herokuapp.com/log_in”(测试环境)会错误地导致404“未找到”错误
似乎测试环境服务器没有加载[root dir]/index.html,因为该文件包含脚本(如果url与任何其他路由不匹配,则包括为“登录”页面提供服务的路由)
有人能告诉我我的测试服务器缺少什么吗?我更喜欢修改“httpd.conf”文件的解决方案,而不是使用.htaccess文件
本地服务器上httpd.conf的代码片段:
DocumentRoot "C:/Sites/myApplication"
<Directory "C:/Sites/myApplication">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
web: vendor/bin/heroku-php-apache2 -C apache_app.conf
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
apache_app.conf:
DocumentRoot "C:/Sites/myApplication"
<Directory "C:/Sites/myApplication">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
web: vendor/bin/heroku-php-apache2 -C apache_app.conf
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]