我想重定向不存在的网页不改变网址的主页。
我在.htaccess文件中使用了以下代码。
ErrorDocument 404 /index.php.htaccess在http上工作得很好(它不会改变网址),但是用https会改变当前的网址。
发布于 2020-05-21 06:03:54
如果希望在发生错误时包含index.php而不更改URL,可以在.htaccess中使用以下代码
ErrorDocument 404 /index.php此代码对http和https有效。
如果想要将http请求重定向到https,可以在.htaccess中添加以下代码
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]发布于 2020-05-21 06:13:23
重定向错误消息:站点将重定向到主页,而不是提示404 Not Found错误页面:
Redirect 404 Error pages to the home page
ErrorDocument 404 http://example.com/将不存在的页面重定向到index.php
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] 您也可以手动将下面的html代码插入到404.php页面。
<head>
<meta http-equiv = "refresh" content = "2; url = https://www.URL.com/404.php" />
</head>https://stackoverflow.com/questions/61923339
复制相似问题