.htaccess RewriteBase for development env not working

时间:2016-08-24 11:21:28

标签: angularjs .htaccess mod-rewrite base-url html5mode

这是我的.htaccess文件

  RewriteEngine On

  RewriteBase /myapp_dev/

  RewriteCond %{REQUEST_URI} /index\.html$ [NC,OR]
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  RewriteRule ^(signup|signin)/?$ $1.html [L,NC]

  RewriteRule ^home/?$ signup.html [L,NC]

  RewriteRule . index.html [L]

在我的html页面中,我有这个

<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <base href="/">
</head>
<body>
  
  <!-- Something here -->
  
  
  <script src="public/libs/angular/angular.js"></script>
  <script src="public/libs/angular-resource/angular-resource.js"></script>
</body>
</html>

我希望服务器请求http://localhost/myapp_dev/public/libs/angular/angular.js

但它要求这个网址无论如何都不存在。

http://localhost/public/libs/angular/angular.js

.htaccess代码中的任何问题?

1 个答案:

答案 0 :(得分:0)

在开发主机上在您的站点根目录中创建一个新的.htaccess ,并有一个额外的规则来处理这些静态路径:

RewriteEngine On

RewriteRule ^public/libs/.+$ /myapp_dev/$0 [L,NC,R=301,NE]