HTACCESS - 页面不存在的问题

问题描述 投票:0回答:1

我有一个我制作的 php 网站,它创建了假(不存在)页面。 如何删除它们并返回 404 页面并重定向至主页?

显示我主页的虚假页面:

/index.html?page=search&sRegion=Dublin
/index.html?page=search&sRegion=Edinburgh
https://www.example.com/?post_type=clients&p=1292

这是我的htaccess:

RewriteEngine On

# add www.
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# external redirect to .html from .php request
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^([^./]+?)\.php$ /$1.html [R=301,L,NC,NE]

# internal rewrite to .php from .html if corresponding php exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
</IfModule>

<FilesMatch ".(ico|css|flv|js|gif|jpeg|png|woff|woff2|eot|svg|ttf|webp)$">
   Header set Cache-Control "max-age=604800, public, no-cache"
</FilesMatch> ```
php .htaccess
1个回答
0
投票

您只需添加以下行即可将所有 404(未找到页面)重定向到您的主页。

ErrorDocument 404 [homepage]

对于您的情况假设您的主页是index.php,然后将以下行添加到您的.htaccess 文件中:

ErrorDocument 404 /index.php
© www.soinside.com 2019 - 2024. All rights reserved.