.htaccess - 如何使用 htaccess 隐藏 URL 上的父文件夹?
问题描述
我已经对这个问题进行了广泛的搜索,但无法找到解决方案。我在本地工作,所以我有这个网址:
http://localhost/IASON/iasongitlab/static_website/html/solutions.html
我设法隐藏了文件扩展名,所以现在我的 URL 是这样的:
http://localhost/IASON/iasongitlab/static_website/html/solutions
但现在我需要从我的 URL 中隐藏 /html/ 文件夹,使它看起来像这样:
http://localhost/IASON/iasongitlab/static_website/solutions
这只是一个例子。我有多个视图,所以我需要在 htaccess 中编写代码来隐藏每个视图上的 /html/ 文件夹。
这是我现在的 htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
我尝试了多种建议但均未成功,希望对解决此问题有任何见解。
解决方案
使用您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。
RewriteEngine ON
RewriteRule ^(IASON/iasongitlab/static_website)/(solutions)/?$ $1/html/$2.html [NC,L]
或者,如果您不想硬编码路径详细信息并solutions
最终在 uri 中查找,那么您可以尝试跟随。确保一次只放置以下或以上规则。
RewriteEngine ON
RewriteRule ^(.*)/(solutions)/?$ $1/html/$2.html [NC,L]
推荐阅读
- r - 从 R 中的列表列表中删除重复项的最佳方法
- python - Django AWS S3 文件未显示在站点上
- bash - 考虑Linux中列的值将矩阵拆分为块
- javascript - LocalStorage 变量不断在两个值之间自行切换,而且没有任何原因——这是 Chrome 的错误吗?
- regex - 正则表达式:匹配两个字符之间的所有内容,除非还被不同的字符包围
- java - 如何使用 Mockito 在 Java 中通过示例模拟 ExampleMatchers
- reactjs - CORS 问题 React Axios
- haskell - 如何在字符串haskell中实现占位符
- python - 表单未在 django 中显示
- javascript - SetInterval 在 Kindle 和 Kobo 浏览器中不起作用