特殊字符与重写规则的htaccess的文件选择重写、特殊字符、规则、文件

2023-09-02 10:08:13 作者:稳拿人心

我犯了一个小错误(我开始在现有的PHP调用中一个新的PHP电话 - 哎呀),并设法把谷歌开始爬一大堆网址看起来像这样:

I made a little mistake (I started a new php call within an existing php call - oops) and managed to have google start crawling a whole bunch of urls that look like this:

http://www.mydomain.com/folder/parameter/%3C/?php%20echo%20writelink();%20%3E

我已经解决了采购电话,但我尝试把.htaccess中的页面调用rewite到

I've fixed the sourcing call, but my attempts to have .htaccess rewite the page calls to

http://www.mydomain.com/folder/parameter/

已经失败。

我已经试过如下:

RewriteRule  ^folder/(.*)/(.*)%(.*) /folder/$1/ [NE,R=301,L]
RewriteRule  ^folder/(.*)/(.*)3C/?php /folder/$1/ [R=301,L]
RewriteRule  ^folder/(.*)/(.*)writelink /folder/$1/ [R=301,L]
RewriteRule  ^folder/(.*)/([^/.]+)writelink /folder/$1/ [R=301,L]

但是,所有的人都返回相同的403。 我有测试重写规则的文件的第一个重写规则,所以它不是被篡夺了别的东西。

But all of them are returning the same 403. I have the test rewriterule as the first rewriterule in the file, so it isnt being usurped by something else.

(仅供参考,当我还没有打乱了页面的正确重写规则是     重写规则^文件夹/(.*)/$ /content/element.php?param=$1 [L] )

(For reference, the correct rewriterule when I havent mucked up the page is RewriteRule ^folder/(.*)/$ /content/element.php?param=$1 [L] )

我之前已经与%年龄问题的路径,但这个时候,我已经决定要打败它 - ?任何建议

I've had problems with %ages in the path before but this time I've decided to defeat it - any suggestions?

推荐答案

您的网址是这样的:

http://www.mydomain.com/folder/parameter/</?php回声writelink(); ?&GT; 的内部消除编码

304 code并没有真正显示一个错误,它表示资源请求的URL自上次访问或缓存并没有改变。清除您的布劳尔的缓存,并确保它被清零。

The 304 code does not really indicate an error, it indicates the resource for the requested URL has not changed since last accessed or cached. Clear your brower's cache and make sure it is cleared.

错误应该是403(禁止)的首字母,因为&LT; (%3C)

The error should be 403 (Forbidden) because of the initial character < (%3C).

这些错误作出任何重写规则在的.htaccess没用。来处理这种问题的一种方法是用一个脚本。

These errors make any rewrite rule at .htaccess useless. One way to handle this kind of problem is with a script.

示例

添加这些行到你的.htaccess文件的根目录下:

Add these lines to your .htaccess file at root directory:

Options +FollowSymlinks -MultiViews
ErrorDocument 403 /Error403.php

通过类似这样的内容创建Error403.php在根目录下:

Create Error403.php at root directory with a content similar to this one:

<?php
// The following lines should be at the top of the file

/**************Only for Debugging**********************/
echo $_SERVER[ 'REDIRECT_QUERY_STRING' ] . "<br /><br />"; 
echo var_dump($_REQUEST) . "<br /><br />";
/*=====================================================
NOTE: A Header error might be generated while the above 
code is active. Use it only to display the incoming 
parameters and delete it for normal operation.
*******************************************************/

if ( isset ( $_SERVER[ 'REDIRECT_QUERY_STRING' ] ) ) {
  $QueryString = $_SERVER[ 'REDIRECT_QUERY_STRING' ]; // The query looks like this: php%20echo%20writelink();%20?%3E 

   // Check if it is the wrong URL
  if ( preg_match( '|php%20echo%20writelink()|i', $QueryString ) ) {
  header("Location: http://www.mydomain.com/folder/parameter/");
  }
}
   // Handle other errors
?>

在我们采取了该字符串中包含一个问号的事实,利用这个具体案例?,这使得它看起来像一个查询。因此,我们尝试匹配的查询内容与 preg_match()

In this specific case we take advantage of the fact that the string contains a question mark ?, that makes it look like a query. So we try to match the query content with preg_match().

这应该这样做。如果需要修改相应的链接,这仅仅是如何做到这一点的例子。

That should do it. Modify the links accordingly if necessary, this is just an example on how to do it.

 
精彩推荐
图片推荐