.htaccess隐藏2个文件夹路径 [英] .htaccess to hide 2 folder paths

查看:156
本文介绍了.htaccess隐藏2个文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难得到关于管理员的第二个声明,我试图隐藏目录的新的和管理部分。新的似乎是隐藏罚款,但管理员不想知道。是新的第一个规则几乎阻止了第二个规则?如果新的或管理员然后隐藏...,可以将两者组合起来?

I am having difficulties getting the second statement working regarding admins, i am trying to hide both new and admin parts of the directory. new seems to be hiding fine however admin doesnt want to know. IS the first rule for new almost blocking the second one? Is it possible to have the two combined so thestatement would read if either new or admins then hide...?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+new/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^new/)^(.*)$ /new/$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admins/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^admins/)^(.*)$ /admins/$1 [L,NC]


推荐答案

您的正则表达式中有语法错误。 char ^ 是您不能匹配的行/字符串的开头,或者在捕获组内部使用它。

You have a syntax error in your regex pattern. The char ^ is a start of line/string you can not match it or use it inside of capture groups.

尝试以下规则:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

##1)Redirect /new/foobar to /foobar##
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+new/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
##2)Redirect /admins/foobar to /foobar##
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admins/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
##1)internally redirect /foobar to /new/foobar##
RewriteCond %{DOCUMENT_ROOT}/new/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/new/$1 -d
RewriteRule ^(.+)$ /new/$1 [L,NC]
##2)internally redirect /foobar to /admins/foobar##
RewriteCond %{DOCUMENT_ROOT}/admins/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/admins/$1 -d
RewriteRule ^(.+)$ /admins/$1 [L,NC]

这篇关于.htaccess隐藏2个文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆