我需要在这里隐藏我的管理文件夹。
http://localhost/elc/admin/dashboard
我需要它来显示http://localhost/elc/dashboard
我的文件夹结构如下:
htdocs
-admin
admin related files
-user
user-related files
-.htaccess
-index.php
这是我迄今为止编写的代码。如果我不包括admin/dashboard,引导程序模板将不起作用。
RewriteEngine on
RewriteRule ^admin/dashboard$ /elc/admin/home.php [NC,L]
#Disabling Directory Browsing
Options -Indexes
ErrorDocument 404 /elc/admin/404.php
ErrorDocument 404 /elc/staff/404.php
我也试过这个。
RewriteRule dashboard$ /elc/admin/home.php [NC,L]
但是,这并不显示引导程序模板。请帮帮我!
此外,我是否必须为网站中的每个链接都写RewriteRule^admin/dashboard$/elc/admin/home.php[NC,L]行?
请按照以下方式获得您的htaccess文件。确保你的htaccess和elc文件夹一起存在于根文件夹中(除此之外,不在elc文件夹中(。
在测试URL之前,请确保清除浏览器缓存。
RewriteEngine on
#Disabling Directory Browsing
Options -Indexes
##External redirect rule from http://localhost:80/elc/admin/dashboard ----> http://localhost:80/elc/dashboard Link here.
RewriteRule ^(elc)/admin/(dashboard)/?$ /$1/$2? [R=301,L,NC]
##Internal rewrite rule to write on home.php file.
RewriteRule ^elc/dashboard/?$ elc/admin/home.php [NC,L]
ErrorDocument 404 /elc/admin/404.php
ErrorDocument 404 /elc/staff/404.php
JS/CS rewrite/redirect:您可能需要使用base标记来修复您的JS和其他相关资源。如果你使用相对路径链接js文件,那么该文件显然会得到404,因为它在寻找URL路径。例如,如果URL路径是/file/而不是file.html,那么您的相对资源是从/file/加载的,该文件不是目录,而是重写的html文件。若要修复此问题,请使链接成为绝对链接或使用基本标记。在你的网页标题中添加这个<base href="/">
,这样你的相关链接就可以从正确的位置加载。