的.htaccess:重写规则问题,如何重定向所有管理面板 [英] .htaccess: Rewrite rule issue, how to redirect all to admin panel
问题描述
我要重定向我的网站管理面板
I want to redirect my website to admin panel
如同
localhost/website/ => localhost/website/admin
localhost/website/login => localhost/website/admin
localhost/website/blog => localhost/website/admin
下面是我创建的规则
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /website/admin/$1 [L]
不过,这是行不通的。
But this is not working
推荐答案
以下code将一切重新定向到您的管理页面,保留的属性。这也适用于已经存在的文件谁!
The following code will redirect everything to your admin page, keeping the attributes. This also applies to files who already exist !
RewriteEngine On
RewriteCond %{REQUEST_URI} !^website/admin
#RewriteCond %{REQUEST_FILENAME} !-f #OPTIONAL: Remove '#' if you want existing files to display normally
#RewriteCond %{REQUEST_FILENAME} !-d #OPTIONAL: Remove '#' if you want existing files to display normally
RewriteRule ^(.*)$ /website/admin/ [L,QSA]
说明:
打开重写引擎:
Explanation:
turn on the rewrite engine:
RewriteEngine On
改写特定条件:URI(域名/本地主机之后的部分)不能(=逆,不!)启动(^ =起始行)与网站/系统管理员
=你在哪里重写。这必须完成,以prevent循环。
specific condition for rewriting: uri (the part after your domain name/localhost) cannot (! = inverse, NOT) start (^ = start of line) with website/admin
= where you are rewriting to. This must be done to prevent looping.
RewriteCond %{REQUEST_URI} !^website/admin
随着2号线可以去掉(删除#),如果你想现有的文件不会被重写
Following 2 lines can be uncommented (remove the #) if you want that existing files are not rewritten
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
在改写自己:
The rewrite himself:
- ^ =行首
- ()=子串
- 。* =一些任意的符号,或无符号
- $ =行尾
- /网站/管理=的地方重写
- [L,QSA] =额外的选项:
- L =最后:停止执行更多的行
-
QSA =查询字符串附加:保持参数,如?页=接触例如。
- ^ = start of line
- () = a substring
- .* = a number of arbitrary symbols, or no symbols
- $ = end of line
- /website/admin = the place to rewrite to
- [L,QSA] = extra options:
- L=last: stop executing further lines
QSA=Query String Append: keep arguments, e.g. ?page=contact e.g.
重写规则^(。*)$ /网站/管理/ [L,QSA]
我希望这澄清了我的解决方案。
I hope this clarifies my solution.
这篇关于的.htaccess:重写规则问题,如何重定向所有管理面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!