我如何通过 .htaccess 隐藏 url 中的子文件夹?

How do I .htaccess to hide the subfolder from url?

我的目录

/main 
      index.php
      /projects 
                /project111
                /project222

例子

示例旧域:http://www.website.com/projects/projectname

示例新域:http://www.website.com/projectname

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/projects
RewriteRule ^/projects/(.*)$ / [L]

请帮助我。

使用 mod_rewrite 并在 .htaccess 中执行替换..

虽然简单地移动文件夹不是更干净吗?

http://www.website.com/projects/.htaccess

添加以下行:

Options +FollowSymlinks
RewriteEngine on

RewriteRule (.*)/?$ http://www.website.com/ [R=301]

()是一个捕获组

. 是任意字符(换行符除外)

*是前面的字符0到任意次数

?是前面的字符0到1次

$ 比赛结束

</code>returns第一个捕获组</p> <p>所以...上面的最后一行将捕获 <code>http://www.website.com/projects/ 之后的所有字符(包括或省略尾部斜杠)并将浏览器重定向到 http://www.website.com/ 后跟同一系列字符。