Home .htaccess, hide sub directories
Reply: 1

.htaccess, hide sub directories

Senka Wolf
1#
Senka Wolf Published in 2017-12-07 22:10:27Z

I am new to learning how .htaccess works and I am struggling on getting it to work how I want it to.

Here is my current .htaccess file:

RewriteOptions inherit

#ErrorDocument 404 https://tsrvtc.com/_pages/404page.html
#ErrorDocument 500 https://tsrvtc.com/_pages/500page.html
#ErrorDocument 403 https://tsrvtc.com/_pages/403page.html

<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on

RedirectMatch 301 ^/?$ https://www.tsrvtc.com/index

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^_pages/)^(.*)$ /_pages/$1 [L,NC]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+vtc_manager/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

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

RewriteCond %{HTTP_HOST} ^tsrvtc\.com$ [NC]
RewriteRule ^(.*)$ http://www.tsrvtc.com/$1 [R=301,L]

</IfModule>
AuthName "public"
AuthUserFile "/home/tsrvtcco/.htpasswds/public_html/passwd"

It currently works hiding the _pages directory in the url but when I try to hide the vtc_managerm directory then goto the page within that directory it redirects to my domain name and puts index.php at the end. The I am given this error: https://gyazo.com/0cc504188657beafd2042d6332e4bd9b

Here is the layout of the directories:

public_html 
  _pages
  vtc_manager

Any assistance will be greatly appreciated.

Ben
2#
Ben Reply to 2017-12-09 02:45:48Z

The error due to misconfigured .htaccess. When you try to dig into it, the apache log shows this error:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

You were making infinite redirects, by these conditions and rules:

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

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

When you made a request / and file is not found in the root directory, then the first condition (1.) meets and rule meets. The request uri is rewritten to /_pages/. The rewritten request is handled, then handed back to the URL parsing engine again. The second attempt, the first condition (1.) meets, but the rule pattern (2.) does not meet. However, the second condition (3.) meets and rule (4.) meets. The request uri is then rewritten to /vtc_manager/_pages/. Then rewritten request is handled and so on.

You should fully read the documentation of mod_rewrite module and RewriteRule Flags to understand what you are trying to do.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304207 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO