简体   繁体   中英

.htaccess to hide 2 folder paths

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]

Exclude directories first, put this before you rewrite conditions

RewriteRule ^(admin|new)($|/) - [L]

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.

Try the following rules :

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM