简体   繁体   English

htaccess从网址隐藏子目录

[英]htaccess hide subdirectory from url

i want to remove/hide the subdirectory "sites" from the url 我想从网址中删除/隐藏子目录“站点”

/profile
  /sites
    login.php
    register.php 
index.php
.htaccess

this: http://localhost/profile/sites/login 这: http:// localhost / profile / sites / login

to this http://localhost/profile/login 到此http:// localhost / profile / login

currently i am using this to hide the .php extension 目前我正在使用它来隐藏.php扩展名

htaccess: htaccess:

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

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/profile/$1.php -f
RewriteRule ^(.+?)/?$ /profile/$1.php [L]

As per your comment on the question, you could simply include the login.php from the base directory to the /sites/login.php. 根据您对问题的评论,您可以简单地将login.php从基本目录添加到/sites/login.php。 This will make this file run like the one in the base directory. 这将使该文件像基本目录中的文件一样运行。 Also see options like include_once(), require(), require_once(). 另请参见诸如include_once(),require(),require_once()之类的选项。

I suggest you use require_once(), and don't see the need for modifying .htaccess file. 我建议您使用require_once(),而不需要修改.htaccess文件。

require_once('../login.php');

UPDATE: as per your comment on this answer, try this in the .htaccess file 更新:根据您对此答案的评论,请在.htaccess文件中尝试此操作

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^sites/(.*)$ http://www.yoursite.com/$1 [R=301,L]

See this link for reference. 请参阅此链接以供参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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