Articles of mod rewrite

如何存储要在Apache中使用的非标准HTTP请求头的值如果有条件的话

我的服务器将收到一个名为EmployeeID的非标准HTTP请求,我想用它来确定对服务器上某些目录的访问权限。 如何存储传入的非标准HTTP请求头的值,以便可以在使用Apache指令的If条件中使用它? 在网上search了很长一段时间后,我想出了以下的地方,我试图使用RewriteRule将头文件保存到一个环境variables中,这样我可以稍后访问variables的值来进行比较。 不幸的是,我只遇到挫折而不是成功。 <Direcory "\Apache24\htdocs\usrs"> RewriteEngine on RewriteRule .* – [E=EmployeeID:%{HTTP:EmployeeID}] <If "{Request_URI} != /%{EmployeeID}/"> Deny from all </If> </Directory">

Apache作为dynamicIP的代理fowarder

我正在寻找networking,但我不知道如何去做我正在寻找的东西。 所以我正在寻找的是一个代理,它将根据我已经放在url(GET)的IP地址前进HTTP查询。 所以,例如: 我请求: http://host/query/IP_A它应该做的是:ME => GET HTTP myhost / query / IP_A => GET IP_A ===> GET IP查询到IP_A并返回给发件人! 我一直在阅读proxypass,reverseproxy,proxymatch和mod_rewrite …但我不明白为什么它不工作! 而我没有日志….这是不是很酷,当debugging时间来了! 🙁 这是我的实际configuration: <VirtualHost *:80> ServerName myServer DocumentRoot /home/me/www/htdocs # RewriteCond ^.*/query/(.*) # RewriteRule (.*) http://$1 [P] ProxyPassMatch ^.*/query/(.*) http://$1 ErrorLog logs/me-error_log CustomLog logs/me-access_log debug </VirtualHost> 这是一个静态工作的例子: ProxyPass / http://IP_A ProxyPassReverse / http://IP_A 所以,当我访问networking服务器,它直接到IP,并返回我的HTTP响应。 […]

在fcgi看到请求之前使mod_rewrite规则进行处理

有没有办法让我的.htaccess文件中的mod_rewrite规则在fcgi后面的PHP看到请求之前生效? 我有一个电子邮件validation链接,我想从根目录redirect到login页面,然后PHP在数据库中将其标记为已确认。 这些是我在.htaccess中的规则,它们工作,但PHP在重写规则生效之前看到请求。 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} activation_key= RewriteRule ^$ /login [R,L] RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 当PHP看到包含activation_key查询string的请求时,会将用户标记为已激活。 如果用户已经激活,页面将显示“未知的validation链接”错误。 使用这些重写规则,请求会redirect到/login页面并显示错误,表明 – 我认为 – PHP已经看到了请求。 这是mod_fastcgiconfiguration: <IfModule mod_fastcgi.c> DirectoryIndex index.html index.shtml index.cgi index.php AddHandler php5-fcgi .php Action php5-fcgi /php5-fcgi Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi […]

htaccess,errordocument和joomla重写

我需要在我的.htaccess中设置一个404error handling,除了处理一些旧网站链接的301redirect。 新网站是用Joomla制作的,旧网站是用asp编写的。 在joomla中启用了url和url重写function。 我需要: 将/old/path/on/old/site/old-page.asp?parameter1=value1&parameter2=value2redirect301至/index.php?option=com_mycomponent&view=myview&parameter1=value1&parameter2=value2 将所有其他未find的文件redirect到/index.php?option=com_content&view=article&id=123&Itemid=456 这几乎成功,但我有一个问题: ErrorDocument指令发送302而不是404。如果我从ErrorDocument中删除了http://www.mywebsite.com ,它将导致Joomla中的错误500,因为当请求page.asp时,它会在查询string,并尝试提供不存在的view.asp.php(我不想创build它只是为了处理问题)。 这是我的htaccess: ## # @package Joomla # @copyright Copyright (C) 2005 – 2013 Open Source Matters. All rights reserved. # @license GNU General Public License version 2 or later; see LICENSE.txt ## ## # READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE! # # […]

别名或redirect或重写

Roundcubemail和Owncloud文件夹位于文档根目录下,但由于Roundcube OwnCloud插件的局限性,我必须按如下方式组织虚拟主机。 $ rcmail_config ['owncloud_url'] =' https: //webmail.whitecube.com/owncloud'; – 该URL不能更改或插件中断。 <VirtualHost 172.21.11.48:8080> ServerAlias "webmail.example.com" DocumentRoot "/var/www/html" </VirtualHost> <VirtualHost 172.21.11.48:8080> ServerAlias "cloud.example.com" DocumentRoot "/var/www/html/owncloud" </VirtualHost> 但是现在请求webmail.example.com会导致文档根目录下的Apachetesting页面,而不是roundcube文件夹。 看来解决这个问题的最优雅的方法是别名到roundcube文件夹,而不是尝试redirect或用roundcubemail重写URL到最后。 我这是正确的,你怎么做? webmail.example.com的请求应映射到/ var / www / html / roundcubmail。 请求cloud.example.com应继续映射到“/ var / www / html / owncloud”。 云必须位于webmail的webroot中,以便插件可以使用它。 我真的只是想要在webail的请求中跳过目录树中的一个级别。

出于性能原因,是否值得围绕Apache的mod_rewrite检查与指令如位置,目录匹配等?

我目前有一些使用mod_rewrite(Apache 2.2)的Apache重写规则。 当我打开重写日志logging时,我看到许多对重写条件的重写条件的评估,这些重写条件不可能与重写条件匹配。 例如,如果我有一系列重写条件没有匹配我的文件/context/chet.js机会,我/context/chet.js应该用某种types的<Location>指令来包围整个块,当我知道的时候会绕过所有的RewriteCond他们都不会匹配来提高性能? 还是重写检查速度快,这样做是不值得的? 用像<Location>这样的指令进行预评估需要多less次重写检查? [23/Sep/2013:12:04:31 –0400] (2) init rewrite engine with requested uri /context/chet.js [23/Sep/2013:12:04:31 –0400] (3) applying pattern '.*' to uri '/context/chet.js' [23/Sep/2013:12:04:31 –0400] (3) applying pattern '^/context/xyz' to uri '/context/chet.js' [23/Sep/2013:12:04:31 –0400] (3) applying pattern '^/context/abc123' to uri '/context/chet.js' [23/Sep/2013:12:04:31 –0400] (3) applying pattern '^/context/testService/(.*)$' to uri '/context/chet.js' [23/Sep/2013:12:04:31 –0400] (3) […]

Apache2的mod_rewrite失败的不存在的子目录

甚至更短版本的.htaccess文件(Last RewriteCond不存在)用于在我的共享虚拟主机上完美工作,但我已经转移到与Ubuntu 12的VPS与它的股票Apache2,但它根本不会工作(甚至与我的变化),我不明白为什么。 我可以访问example.com或example.com/news,但不能访问example.com/article/4 我把mod_rewrite块从.htaccess到vhostconfiguration,反之亦然,但似乎没有工作。 我猜它实际上试图去到文章的子目录或东西(这不存在如此404),但我不知道如何阻止它做到这一点。 我正在使用Apache版本2.2.22 我的虚拟主机文件 <VirtualHost 127.0.0.1:80> DocumentRoot /home/example/www/example.com RewriteLogLevel 3 RewriteLog /home/example/www/example.rewrite.log <Directory "/home/example/www/example.com"> AllowOverride All Options -ExecCGI +FollowSymLinks -Indexes -MultiViews Order deny,allow allow from all <IfModule mod_rewrite.c> RewriteEngine On RewriteOptions inherit </IfModule> </Directory> AccessFileName .htaccess ServerSignature Off ServerName example.com ErrorLog /home/example/www/example.log LogLevel warn </VirtualHost> 我的.htaccess文件 ErrorDocument 404 /index.php?404 ErrorDocument 403 […]

Apache的URLredirect可以向原始URL和重写的URL发送请求吗?

我想使用Apache的URLredirect来匹配一个URL,并将请求转发给另一个URL。 很简单,我知道。 但是,我希望继续调用最初请求的URL以及重写的URL。 这可能使用Apache的URL重写设施? 或者URL重写受到限制,始终用重写的URLreplace原始URL? 谢谢

基于User-Agent的服务器级别阻止,拒绝或redirect?

我们最近开始遇到networking刮板/ DDoS服务的80个问题,因为他们滥用爬取的做法,每周都会把我们的服务器closures几次。 最初,我们只是在受影响的网站的.htaccess文件的底部放置以下内容: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_USER_AGENT} ^.*80legs RewriteRule .* – [F,L] </IfModule> 但是,我们只是需要在所有服务器的服务器级别阻止它们。 根据Apache文档,这个configuration是有效的放置在服务器configuration部分,又名httpd.conf ,但这样做没有效果。 在启用了虚拟主机的Apache服务器上,是否有一种特殊的方法可以阻止/拒绝/redirect基于用户代理的请求? 注意:在防火墙级别是不可能的,因为: 80legs使用本质上是一个select在僵尸networking爬行页面。 他们最后的“事件”涉及来自全球约900个不同networking/ IP块的5250个独特IP。 目前我们还没有能力进行深度包检测。

apache mod_rewrite子规则和宁静结构

我试图设置几个重写规则,允许一个宁静的url结构存在,但只在一个特定的子域。 几个子域名已经指向共享的代码库。 我也有一个现有的重写,以使用PHP smarty,它已经捕捉了一切。 所有子域名,包括宁静的域名,都需要redirect到最后一步。 最后,为了方便起见,我想尽可能将子域放入一个查询stringvariables中,以避免试图稍后以编程方式提取它。 我是mod_rewrite的新手,并且难以让所有这些工作在一起…这是我迄今为止的混合尝试,这并不完全合作。 # copy subdomain to variable. # ideally though, dev.subdomain.domain.com would only copy "subdomain", not "dev.subdomain". # this should work for all subdomain, and keep going. RewriteCond %{HTTP_HOST} (.+).domain.com [NC] RewriteRule / /$1?subdomain=%1 [QSA] # restful api, only for restful.domain.com. how to apply to all rules? RewriteCond %{HTTP_HOST} restful.domain.com […]