尾随斜杠htaccess用于保护管理目录

时间:2013-04-09 20:01:03

标签: .htaccess mod-rewrite redirect trailing-slash

我打电话给domain.net/about-us来了domain.net/about-us/(添加tralin斜线)正确的页面!

我调用了domain.net/admin或domain.net/admin/,错误是404

当我添加此行注释时

#RewriteRule .*[^/]$ $0/ [L,R=301]

出现并要求输入密码管理文件夹。

但是我打电话给domain.net/about-us(不要尾随斜线)来了404

等待你的帮助,谢谢。

穆拉特

我的root htaccess文件:

...
RewriteEngine ON
RewriteBase /

RewriteRule ^index.php$ - [L]

#add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*[^/]$ $0/ [L,R=301]
...
RewriteRule ^about-us/$ index.php?p=cont&sef=about-us [L,NC]
...

admin文件夹(保护)htaccess文件:

AuthName "admin"
AuthUserFile "/home/xxxxxxx/.htpasswds/public_html/admin/passwd"
AuthType Basic
require valid-user

1 个答案:

答案 0 :(得分:0)

请为这些配置指令进行测试:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-_]+)$ /$1/ [R]

RewriteRule ^about-us/$ /index.php?p=cont&sef=about-us [L,NC]

# try to add this rule
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)$ /$1/$2/ [R]