htaccess重写为index.html或admin.html [英] Htaccess rewrite to index.html or admin.html

查看:44
本文介绍了htaccess重写为index.html或admin.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将AngularJS的路由模块用于我的WebApp,它的运行效果很好.但是我希望当用户重新加载/Category/1 之类的页面时,他将使用/Category/1 重定向到 index.html 作为参数.工作正常.

I use the routing module of AngularJS for my WebApp and it works great. But I want that when the user reload a page like /Category/1, he will be redirected to index.html with /Category/1 as parameters. This is working.

但是当我想添加一个管理界面时,它就坏了...

But when I want to add an admin interface, it brokes...

这是我的文件夹:

  • index.html
  • admin.html
  • 一些angularjs文件夹...

还有我的.htaccess文件:

And my .htaccess file :

<IfModule mod_rewrite.c>
 # Redirect /index.html to / 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html
    RewriteRule ^index.html/?(.*)$ $1 [R=301,L]

 # Run everything that contains /admin/ but real files through admin.html
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{THE_REQUEST} .*/admin/.*
    RewriteRule ^admin/(.*)$ admin.html/$1?%{QUERY_STRING} [L]

 # Run everything else but real files through index.html
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /$1?%{QUERY_STRING} [L]

</IfModule>

当我转到/admin/Category/1时,它尝试访问名为admin.html/Category/1的文件夹,显然失败了...

When i go to /admin/Category/1, it tries to access a folder named admin.html/Category/1, and obviously it fails...

我做错了什么?

推荐答案

通过以下代码替换您的规则:

Replace your rules by this code:

<IfModule mod_rewrite.c>
 # Redirect /index.html to / 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html
    RewriteRule ^index.html(/.*)?$ $1 [R=301,L]

 # Run everything that contains /admin/ but real files through admin.html
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{THE_REQUEST} /admin/
    RewriteRule ^admin/(.*)$ admin.html?$1 [L,QSA]

 # Run everything else but real files through index.html
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ /?$1 [L,QSA]

</IfModule>

这篇关于htaccess重写为index.html或admin.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆