htaccess管理面板的重写规则 [英] htaccess rewrite rule for admin panel
问题描述
我的Web应用程序中具有url模式,例如 www.mysitename.com/foldername/controller/method 。
然后将所有请求的页面都首先重定向到根文件夹上的index.php,然后处理请求的页面。
,但是每当我转到管理面板( www.mysitename.com/admin )时,该网址都会将 admin作为文件夹名称,并向我显示admin的index.php, (以这种方式很正常),然后使用 controllername (控制器名称)或 methodname (方法名称),它不会通过管理文件夹的index.php进行重定向。
I have the url pattern in my web application like this "www.mysitename.com/foldername/controller/method". And all requested pages are redirected to index.php first on root folder and then it process the requested pages. but whenever i go to admin panel (www.mysitename.com/admin) the url gets the "admin" as a folder name and it shows me the index.php of the admin, (thats normal in this way) then with controllername or methodname it does not redirect through the index.php of the admin folder.
每当我访问管理员时,我都希望使用这种模式的网址 www.mysitename.com/admin/foldername/controller/method 。以及通过admin请求的所有
页面都应首先重定向到admin文件夹上的index.php。
这是我的htaccess文件-
I want the url in this pattern "www.mysitename.com/admin/foldername/controller/method", whenever i visit the "admin". As well as the all requested pages through admin should be redirected to the index.php on admin folder first. here is my htaccess file -
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
推荐答案
您在管理目录中有一个 .htaccess
文件,还是在根目录中只有一个?您需要在每个目录中都有一个。
Do you have an .htaccess
file in your admin directory, or just one in the root directory? You need to have one in each directory.
我刚刚使用<$ c $中的 .htaccess
测试了此文件c> / htdocs / pro 和 / htdocs / pro / admin
.htaccess >并完全按照您的解释工作。
I just tested this with your .htaccess
in /htdocs/pro
and the same .htaccess
in /htdocs/pro/admin
and it worked exactly as you explained.
/htdocs/pro/.htaccess中的root htaccess
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
/htdocs/pro/admin/.htaccess中的管理员htaccess
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
/htdocs/.htaccess
或<$ c $中的单个htaccess文件c> /htdocs/pro/.htaccess
Options -Indexes
RewriteEngine on
# Change '/pro/' if directory is renamed
RewriteBase /pro/
# Change the '/pro/' portion of the condition if directory is renamed
RewriteCond %{REQUEST_URI} ^/pro/admin(.+)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ admin/index.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
这篇关于htaccess管理面板的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!