Articles of mod rewrite

成千上万的HTTP_REFERER不存在的域请求

在过去的几天里,我的一个网站每分钟都收到数百个请求,其中不存在随机域名为HTTP_REFERER和来自不同IP(因此使用deny from IP不是一个选项): REMOTE_ADDR | HTTP_REFERER | HTTP_USER_AGENT 95.133.126.178 | 1dljlc2jm2.info | Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; QihooBot 1.0 [email protected]) 188.232.31.38 | 3r28169e6v4.net | Mozilla/5.0 (compatible; ShunixBot/1.x; http://www.7vlc8pngqk7zmx.com/bot.htm) 177.184.135.114 | 3p10jjujbn.ru | Mozilla/5.0 (compatible; Bot; +http://w4n2e2mte8.ws/spamfilter 188.235.184.231 | 06d94hx.biz | Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; iRider 2.21.1108; FDM) 42.119.240.12 | ho0gg8r7.net […]

Laravel和WordPress在相同的服务器/域

我正在尝试在Laravel(5.1)项目中托pipe一个WordPress站点。 我有以下结构(剥离了一些) ├── app ├── config ├── public │ ├── index.php │ ├── wordpress -> ../wordpress │ └── .htaccess ├── resources ├── storage ├── vendor └── wordpress ├── index.php ├── wp-admin ├── wp-config.php ├── wp-includes └── .htaccess 虚拟文档根目录是公共的。 WordPress的应该抓住一切通过.htaccess跌落。 但是,例如/login应该去laravel。 当我的项目增长时,我打算添加更多的规则来捕捉Laravel的请求。 我在/ public中有以下.htaccess文件: <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d […]

转发到https保持URL完整/完整

我想转发所有stream量到https。 在URL中可以有子域名和子域名保持不变。 例: http://subdomain.myDomain.me -> https://subdomain.myDomain.me http://myDomain.me/subpath -> https://myDomain.me/subpath http://subdomain.myDomain.me/subpath -> https://subdomain.myDomain.me/subpath 我在这个整齐的评估器 (从这里链接)中使用以下代码尝试的例子: RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https:/$1 在评估者中,一切都很好。 真正的虚拟主机是这样的: <virtualHost *:80> ServerName myDomain.me RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https:/$1 </VirtualHost> 当试图访问真实网站时,发生这种情况: http://subdomain.myDomain.me -> http://subdomain.myDomain.me # fail – no https http://myDomain.me/subpath -> https://myDomain.mesubpath # fail – subpath appended to top-level domain […]

在Apache mod重写中dynamic设置RequestHeader主机

我正在使用Apache mod_rewrite,我正在寻找基于QUERY_STRING的域dynamic设置RequestHeader的Host头。 我将如何dynamic设置Host ? 鉴于以下请求URL: https://example.com/p12?url=http://nonssldomain.com/331551/1041505584.jpg?dt=032620151151 我试过了: RewriteCond %{QUERY_STRING} ^url=(.*)$ [NC] #some regex to parse domain from Query_String (Doesn't work) RequestHeader set Host ^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+) RewriteRule ^.*/p12$ %1? [P,NC,L] 我需要dynamic设置一个variables吗?

在php-fpm处理之前将所有* .php重写为单个index.php(apache)

传统应用程序通过Slim框架传递所有传统的PHP文件请求到index.php在.htaccess文件。 此外,Symfony应用程序在设置了别名的文件夹中设置。 用PHP-FPM进行VHostconfiguration <VirtualHost *:80> ServerName example.com DocumentRoot /path/to/app/slim Alias /system /path/to/app/symfony <IfModule mpm_itk_module> AssignUserId web_user web_user </IfModule> <LocationMatch "^(.*\.php)$"> ProxyPass fcgi://127.0.0.1:9001/path/to/app/slim </LocationMatch> </VirtualHost> testing文件: /path/to/slim/index.php <?php echo "slim"; /path/to/slim/.htaccess RewriteEngine On RewriteBase / RewriteRule ^hello$ /hello.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] /path/to/slim/hello.php: <?php echo "hello"; /path/to/symfony/app.php <?php echo "symfony"; […]

使用mod_rewrite阻止apache模式下的机器人请求。 mod_rewrite无法正常工作

我试图在apache上通过模式glitter_calendar来阻止机器人的请求。 史前史。 我的服务器被机器人大量访问。 请求URI是… glitter_calendar .. wordpress返回404.服务器甚至每周下降一次。 我试图用Fail2ban阻止他们。 没有成功。 服务器负载不下降,我得到新的主机不断出现在我的iptables块规则。 在我的.htaccess我试图通过模式glitter_calendar添加一个块规则: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{THE_REQUEST} ^.*(wpdffcontent)|(glitter_calendar)|(mp4:).* [NC] RewriteRule ^(.*)$ – [F,L] </IfModule> <Files xmlrpc.php> Order Deny,Allow […]

loggingapache 2.2和apache 2.4之间的redirect

在这里遇到了一个问题,我find了很less的信息,我希望有人能够说明一些问题。 我正在升级服务器从Apache 2.2到Apache 2.4。 在该服务器中,有一个设置可以在apacheconfiguration中redirect到其他本地托pipe的站点。 该设置的问题是它使用指令RewriteLog和RewriteLogLevel将输出redirect到一个单独的日志,而不是通常的主机日志。 阅读两个版本的Apache(2.2与2.4)之间的变化,看起来像RewriteLog和RewriteLogLevel已被弃用,并用mod_rewrite取代。 这一切都很好,但我没有find在mod_rewrite中提到的一个函数,它允许我定义一个单独的日志文件来写出在Apache中的该网站的重写调用。 有没有人有任何有用的提示或可以指出我在一个很好的方向,可以解释如何redirect输出到mod_rewrite内的新日志? 谢谢!

使用Apache,将stream量重写到文件夹,然后redirect来自该文件夹的所有stream量

我有一个网站,目前正在从一个旧的CMS迁移到一个新的(Laravel)。 只有一些网站的语言已经被转移到Laravel。 所以基本上,我的虚拟主机的根文件夹是这样的: [D] staticContentDirectory1 [D] staticContentDirectory2 … [D] oldCmsDirectory1 [D] oldCmsDirectory2 … [D] oldCmsDirectoryN [D] public [F] index-of-the-old-cms-still-in-use.php 我有一个.htaccess文件,将旧CMS或静态内容目录中没有处理的所有内容redirect到Laravel,如下所示: RewriteRule ^((?!staticContentDirectory1|staticContentDirectory2|public)(.*))$ public/$1 [L] Laravel也有公开的.htaccess来处理它的东西。 到目前为止,一切工作都很完美,我们对结果非常满意(给定初始约束条件)。 我们发现了一个问题。 不知何故,谷歌设法发现/public存在并抓取它,导致与/public/里面,从那以后创build/public/public/ URLs(幸运的是,返回一个500错误,避免无限的URL)。 在修复CMS和robots.txt之前,我们试图通过将stream量从/public重写/redirect到/来解决这个问题。 很多事情都经过了尝试,发生了很多失败,几乎全部都是无限循环的redirect。 因为每个Apache模块似乎都是自己做的,混合RedirectMatch和RewriteRule失败了。 RewriteCond和RewriteRule是无限的redirect或完全忽略。 TL; DR:我现在正在寻求帮助:如何将RewriteRule /folder到/folder ,然后将所有stream量从该文件夹redirect到根目录。

.htaccess代码来阻止所有的.ua域名,但白名单一个特定的域名

我使用以下.htaccess代码阻止了一些垃圾邮件引用者: RewriteCond %{HTTP_REFERER} \.ru$ [NC,OR] RewriteCond %{HTTP_REFERER} \.ru/ [NC,OR] RewriteCond %{HTTP_REFERER} \.ua$ [NC,OR] RewriteCond %{HTTP_REFERER} \.ua/ [NC,OR] RewriteCond %{HTTP_REFERER} hol\.es [NC,OR] RewriteCond %{HTTP_REFERER} hys\.cz [NC,OR] A few more similar lines RewriteCond %{HTTP_REFERER} slinqs\.com [NC] RewriteRule ^(.*)$ – [F,L] 正如你所看到的,我使用代码阻止了所有的.ru和所有的.ua域名。 问题是现在我想允许一个特定的.ua域发送stream量到我的网站。 我如何将一个.ua域名列入白名单? 可能吗?

htaccess取代了完整的URL而不是REQUEST_URI

我正在做一些应该很简单的事情,但是第二天就会碰壁。 urlredirect要求是: 非www => www 非https => https /file.html => /utilities/template_handler.php?filename=file.html 问题:当我要求https://example.com/file.html我得到r = 301到 https://example.com/utilities/template_handler.php?filename=https://www.example.com/file.html 我的.htaccess : RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301] RewriteRule ^(.*)\.html$ /utilities/template_handler.php?filename=$1.html [NC] 我使用litespeed web服务器,但为了解决故障的目的也设置了Apache,结果也是一样。 打开debugging后,我看到: strip base: '/' from URI: '/file.html' Rule: Match 'file.html' with pattern '.*', […]