gpt4 book ai didi

php - .htaccess-页面没有正确重定向

转载 作者:行者123 更新时间:2023-11-28 00:50:04 26 4
gpt4 key购买 nike

我正在尝试将 index.html 重定向到 home.html 并通过 .htaccess 从 url 中删除 home.html。但它显示该页面未正确重定向。这意味着我需要将 mydomain.com/index.html 重定向到 mydomain.com/home.html 并且我需要仅在访问索引页面时显示 mydomain.com/。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 "/index.html" "/home.html"

RewriteCond %{THE_REQUEST} ^GET.*home\.html [NC]
RewriteRule (.*?)home\.html/*(.*) /$1$2 [R=301,NE,L]

</IfModule>

最佳答案

您可以尝试设置 DirectoryIndex 而不是使用 mod_rewrite| 到所需的页面(在您的例子中是 home.html):

DirectoryIndex home.html

因此,如果您调用 domain.com/,它应该为您提供 domain.com/home.html

的内容

作为引用,Apache 配置手册: https://httpd.apache.org/docs/2.4/mod/mod_dir.html“DirectoryIndex 指令”


引用下面的对话:

也许这可行(抱歉,我现在无法测试)

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} =/index.html
RewriteRule (.*?)home\.html/*(.*) /$1$2 [R=301,NE,L]

一点解释:如果请求的主机匹配 example.com 并且调用的 URI 实际上不是真实的文件或文件夹加上 URI 等于"index.html"它应该重定向到 home.html。

编辑:由于您不想显示 home.html,我们也许可以通过在内部“代理”请求而不是强制外部重定向来逃脱。尝试将最后一行(RewriteRule)中的“R=301”替换为“P”,这样它就会显示 RewriteRule (.*?)home\.html/*(.*)/$1$2 [P,NE, L]

关于php - .htaccess-页面没有正确重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47990852/

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