问题
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...
Here is my folder :
- index.html
- admin.html
- Some angularjs folders...
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>
When i go to /admin/Category/1, it tries to access a folder named admin.html/Category/1, and obviously it fails...
What did I do wrong ?
回答1:
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>
回答2:
Urls provided by AngularJS :
- home: http://www.example.com/
- category : http://www.example.com/Category/
- Article 1 in Category : http://www.example.com/Category/1
- admin : http://www.example.com/admin/
- category in admin : http://www.example.com/admin/Category
- Article 1 in Category in Admin : http://www.example.com/admin/Category/1
With your htaccess, when I ask for the Category in Admin, AngularJS send me the admin page only. I think the problem comes from the admin.html**?**$(1)...
来源:https://stackoverflow.com/questions/27145640/htaccess-rewrite-to-index-html-or-admin-html