我遇到了 .htaccess 的另一个问题,我似乎无法找到正确的解决方案。我试图做到的是从一个子目录重定向到一个特定的HTML文档中的同一个目录,当你复制/粘贴的URL显示在下方
例如:http://example.com/staging/测试/到http://example.com/staging/测试/ page.html中
我的(几乎)工作方法:
Options -Indexes -MultiViews
RewriteEngine on
RewriteRule ^test/(.*)$ test/page.html [L]
这段代码的问题在于它基本上重定向到正确的page.html但如果你想点击 page.html 上的任何链接,它只会再次重定向到 page.html 而不是转到子目录 /test/ 中的特定链接假设/test/page-2.html
重要提示:此重定向应仅影响子目录“暂存”。包括 root 在内的所有其他子目录都不会受到影响。
其他信息:此代码也在我的 .htaccess 文件中,用于删除目录“暂存”的 .html 扩展名
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]
目录“staging”未连接到任何 CMS,仅包含 .html 文件。我在共享托管环境 (Hostgator/cPanel) 中。
谢谢你。
使用以下规则,您仅使用 L 标志,但我正在修改它以进行您提到的重定向。
Options -Indexes -MultiViews
RewriteEngine on
RewriteRule ^test/$ /staging/test/page.html [R=301,L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句