简体   繁体   English

如何使用htaccess从URL隐藏文件夹?

[英]How to hide a folder from the URL using htaccess?

I need to hide the "modules" folder from the url "www.domain.com/modules/demo/add.php" I have written the following htaccess code, 我需要从网址“ www.domain.com/modules/demo/add.php”中隐藏“模块”文件夹,我编写了以下htaccess代码,

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

RewriteRule ^modules/(.*)$ /$1 [L,NC,R]

After using the same .htaccess code, I found 404 error. 使用相同的.htaccess代码后,我发现404错误。 (you can check the demo @ http://crmdemoserver.com/modules/demo/add.php (您可以查看演示@ http://crmdemoserver.com/modules/demo/add.php

Well you should think of it the other way around. 好吧,您应该反过来考虑它。 Link this file only without the modules directory. 仅在没有模块目录的情况下链接此文件。 In the .htaccess you can then simply do the following: 然后,您可以在.htaccess中执行以下操作:

RewriteEngine on
RewriteBase /

RewriteRule ^demo/(.*)$ /modules/demo/$1 [L,QSA]

The .htaccess will be lying in the / directory. .htaccess文件将位于/目录中。

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

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