我有一个我制作的 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> ```
您只需添加以下行即可将所有 404(未找到页面)重定向到您的主页。
ErrorDocument 404 [homepage]
对于您的情况假设您的主页是index.php,然后将以下行添加到您的.htaccess 文件中:
ErrorDocument 404 /index.php