简体   繁体   中英

Filtering pages to redirect to 404 in .htaccess

I have a site that use to have a search engine script on it, that has been removed and replaced with new content.

Every so often the site gets flooded with requests like:

/index.php?page=search/web/appdojo.com

/index.php?page=search/web/2tu.us

/index.php?page=search/emailafriend&url=http%253A%252F%252F

/index.php?page=user/viewcomments/images/82e10127b84ee2750c

This then causes a huge amount of processes to start up and then we have problems with the hosting provider.

I'm thinking I should be able to stop these in .htaccess before index.php is called but haven't figured out a regex expression to do that but to let the rest of the index.php url's to pass through OK.

Can anyone help out? -thanks

Since you include PHP in your tags, it would be far easier to simply show a 404 error on the index.php and make it seem to be an error. So you can put this before everything on the index.php page:

if (isset($_GET['page'])) {
    header('HTTP/1.0 404 Not Found');
    include('404.php'); //Whatever your 404 error page is
    exit();
}

如果您的索引页面根本没有使用page变量,则可以尝试阻止所有在URL中具有页面参数的URL

RewriteRule ^index.php?page= /Your_404_page.php

Yes it is better to stop them at .htaccess stage to prevent loading PHP. Here is the rule that will work for you in DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php\?page= [NC]
RewriteRule ^ - [R=304,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM