gpt4 book ai didi

apache - 如何使用 .htaccess 将重定向子目录合并到根目录并同时删除 HTML 扩展名?

转载 作者:行者123 更新时间:2023-12-04 03:49:09 25 4
gpt4 key购买 nike

我尝试将重定向子目录合并到根目录并使用 .htaccess 删除 .html

但是我的事件有问题

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# RedirectMatch 301 ^/path/$ http://testdomain.com/
# RedirectMatch permanent ^/path/$ http://testdomain.com/
# RedirectMatch 301 ^/path/.*$ http://testdomain.com/
# RewriteRule ^path/(.*)$ /$1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

</IfModule>

我对从链接的扩展名中删除 .html 并获得结果没有任何问题

但是我无法在根目录中获取子目录链接,我每次都尝试清除前 4 行中的#但我没有得到结果

我需要这样做

http://testdomain.com/path/hello.html
to
http://testdomain.com/hello

现在使用这段代码,我可以删除 HTML 扩展,我的链接状态如下

http://testdomain.com/path/hello.html
TO
http://testdomain.com/path/hello

现在我需要清除链接中的“路径”文件夹

同时,我收到错误 404 Not Found,请指导我。

最佳答案

您可以用此规则替换您的规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/path/$1.html -f
RewriteRule ^(.+?)/?$ path/$1.html [L]

关于apache - 如何使用 .htaccess 将重定向子目录合并到根目录并同时删除 HTML 扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64680742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com