首页 文章

.htaccess阻止包含点的网址

提问于
浏览
0

我有这个 .htaccess 文件

DirectoryIndex index.php
RewriteEngine On

RewriteBase /



########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#
#Order allow,deny
#Deny from all
#Satisfy all
#
## End of deny access to extension xml files
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a  tag in URL
RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

我不知道为什么,但如果我在网址中有一个点,服务器会显示Url Not Found错误,而不是将我重定向到index.php .

我想用点启用网址,我该怎么办?

1 回答

  • 1

    在这条规则中

    RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$
    

    这部分 /[^.]* 阻止请求URI中的任何点 . 尝试删除它或设置为 /[^/.]+

    似乎这个规则 (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*) 旨在仅允许具有有限扩展名的网址[.php,.html,.htm,.feed,.pdf,.raw] . 但它的最后一部分 /[^.]* 似乎错了 . 它会检查斜杠后是否有除dot之外的任何符号 . 但规则 [^.] 也可能包含斜杠 . 我想这部分的意图是允许在最后一节中没有点的网址 . 所以我建议你使用 /[^/.]+ .

    由于你想在任何位置使用点,它就像允许任何扩展一样 . 所以这条线根本没有意义 .

相关问题