【发布时间】:2017-12-07 22:10:27
【问题描述】:
我刚开始学习 .htaccess 的工作原理,我正在努力让它按我想要的方式工作。
这是我当前的 .htaccess 文件:
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"
它目前可以在 url 中隐藏 _pages 目录,但是当我尝试隐藏 vtc_managerm 目录然后转到该目录中的页面时,它会重定向到我的域名并将 index.php 放在最后。我收到此错误:https://gyazo.com/0cc504188657beafd2042d6332e4bd9b
这是目录的布局:
public_html
_pages
vtc_manager
任何帮助将不胜感激。
【问题讨论】:
-
你可以举一个访问vtc_manager时请求url的例子吗?
-
嗨 Ben,我使用的 URL 是 www.tsrvtc.com/vtc_manager/index.php。 index.php 文件位于 vtc_manager 目录中,在 public_html 目录中,主页是 index.html。我什至尝试将 index.html 重命名为 home.html,但它仍然给我他 gyazo 链接中的错误。
-
您能解释一下您的期望吗?您是否要同时将
/设为/_pages和/vtc_manager的别名? -
我只是想从 URL 中隐藏 '/_pages' 和 '/vtc_manager' 目录。
-
您将
/设为/_pages的别名,并且无法为另一个页面创建别名,在这种情况下为/vtc_manager。由于重定向配置错误,您正在使 .htaccess 无限重定向,因此它会导致内部服务器错误。
标签: .htaccess mod-rewrite