.htaccess - 使用 .htaccess 在 URL 中隐藏文件夹
问题描述
如何将我的 URL 从显示:更改www.example.com/p/tools
为仅www.example.com/tools
?
我尝试过使用 .htaccess ,但不幸的是无法使其工作。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
</IfModule>
解决方案
根据您显示的示例,您能否尝试以下操作。
请确保在测试您的 URL 之前清除您的浏览器缓存
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteRule ^p/(.*)/?$ $1 [NC,R=301,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
</IfModule>
推荐阅读
- python - 如何使用 css 选择器或任何其他定位器 selenium python 查找具有特定类属性的元素
- python - 如何在 Python 中从同一个字符串中提取多个名称
- r - 收到警告:在 R 中的 LDA 预测中,«'newdata' 有 150 行,但发现的变量有 350 行»
- python - 使用 numpy 的变量之间的相关性
- android - 等到 firebase 获取数据以继续(Kotlin)
- c++ - C++ - 使用 strcmp 比较哪个名称按字母顺序排在第一位
- flutter - 如何在颤动中压缩或减小 gif 文件的大小?
- python - 在单变量时间序列建模中生成观测值
- git - 同一个域,多个没有 ssh 的 git 帐户
- c# - 为什么一个物体在另一个物体下的孩子比例不一样?以及如何将对象缩放为相同大小?