Articles of mod rewrite

mod_rewrite应该提供存在于文档根目录但是忽略它们的文件

我已经从Wordpress中解除了大部分,所以像say /search或/list这样的域名的任何path都被定向到/index.php 。 很好,工作。 但是,如果请求的文件存在于文档根目录中 ,则不应该这样做。 所以,如果我请求/exists.php它应该运行该脚本。 相反,它忽略了文件系统上的文件,并继续为index.php服务。 <VirtualHost *:80> DocumentRoot /home/sites/dev ServerName dev.vbox RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . /index.php ErrorLog /var/log/apache2/dev.error.log </VirtualHost> 我已经通过mod_rewrite文档和各种谷歌search结果,但我没有看到我的重写条件有什么问题。 如果请求的文件名是文件或目录,请不要redirect到/index.php 。 我已经cd到doc根目录,并列出了该目录的内容,我请求的文件存在。 我的apache访问日志有/exists.php条目。 文档根目录是安装在我的Mac上的目录,服务请求的虚拟机是Ubuntu安装。

重写地图(prg :)永远不会结束

使用Apache和一个prgtypes的重写映射。 我的地图看起来像: #!/usr/bin/perl $| = 1; # Turn off buffering while (<STDIN>) { print "someothersite.com"; } 在httpd.conf中声明的重写规则是: RewriteMap app_map prg:/file/path/test.pl RewriteRule (\/[\w]+)(\/[^\#\s]+)?$ http://${app_map:$1}$2 [P,L] 日志文件显示: init rewrite engine with requested uri /a/testlink.html applying pattern '(\/[\w]+)(\/[^\#\s]+)?$' to uri '/a/testlink.html' 看起来像test.pl从来没有把控制权交给Apache,当地图成功find我期望在日志文件中看到这个输出: map lookup OK: map=app_map key=/a -> val=someothersite.com 为什么我的地图不能将控制权返回给Apache?

当省略尾部斜线时,Apache请求包含完整的物理path

我最初的目标是重写请求http://server.com/node/XXXXX http://server.com/node/index.cgi?XXXXX 。 node实际上是一个包含index.cgi的物理目录,位于文档根目录下。 这一点相当简单: AddHandler cgi-script .cgi Options +FollowSymLinks +ExecCGI RewriteEngine On RewriteBase /node RewriteCond %{REQUEST_FILENAME} !index.cgi RewriteRule ^(.*)$ /node/index.cgi?$1 [L,QSA] … /real/path/to/web/stuff/node下的.htaccess文件中。 请注意,这意味着请求的formshttp://server.com/node/提供一个空的查询stringindex.cgi ,这是我想要的。 所以现在是棘手的部分:我想请求http://server.com/noderedirect到http://server.com/node/ – 如上所述,redirect到index.cgi与一个空的QS。 麻烦的是,如果我没有任何规则在我的根目录, http://server.com/node //server.com/node确实似乎去http://server.com/node/ – 但我发现给index.cgi的查询string是与请求对应的完整物理path( /real/path/to/web/stuff/node )! 我试过一个规则,在我的根级 .htaccess像: RewriteCond %{REQUEST_URI} =/node RewriteRule ^(.*)$ /node/ [L] # (also tried [L,R=302]) 但是这没有效果。 我知道,Apache做了一些尾随斜线附加在引擎盖下,但我不能使用DirectorySlash Off …我不想如果我可以,因为我有一个Drupal安装驻留在根(有一个如果类似的重写规则在那里,但我不认为他们干涉)。 那么是否可以创build一个适用于根目录.htaccess的规则,或者修改/node/.htaccess来使其不重要? 即使身体移动也不是没有道理的。 […]

Apache mod_jkreplacemod_rewrite规则

我们在Tomcat 6.0实例之前有一个稍微复杂的Apache 2.2安装程序。 主要的Tomcat webapp部署在: /opt/tomcat/webapps/ROOT 但是我们也有半定期更新的静态内容。 我们不想强制一个新的构build和部署的Web应用程序,所以这是分开存储在如下文件夹: /opt/tomcat/webapps/css /opt/tomcat/webapps/foo /opt/tomcat/webapps/bar 为了从Apache处理这个问题,我们使用mod_rewrite,规则如下所示: RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/css/(.*)$ – [L] RewriteCond ROOT/%{REQUEST_FILENAME} -f RewriteRule ^/css/(.*)$ ROOT/$1 [L] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^(.*)\.(jpg|png|html|js)$ – [L] RewriteCond ROOT/%{REQUEST_FILENAME} -f RewriteRule ^(.*)\.(jpg|png|html|js)$ – [L] RewriteRule ^/(.*)$ http://localhost:8080/$1 [P,L] ProxyPassReverse / http://localhost:8080/ 我现在想我可能要开始使用mod_jk,我有两个问题: 它甚至值得使用mod_jk吗? 我不需要负载平衡。 是否有可能处理我列出的静态内容被引用为“ http://www.example.com/css/foo.css ”的情况,但我们不知道它是否位于Tomcat webapp或其中一个静态文件夹。

在Apache Rewrite / SetEnvIf(content type,expires headers)中访问HTTP响应?

是否可以访问Apache中的响应对象数据? SetEnvIf之后 的RewriteCond …以便可以根据内容types和caching输出来操作标题? 从文档看来,这是不可能的。 有没有其他模块可以允许这种types的操作(根据响应头设置环境variables)?

nginx如果指令从0.7升级到1.0.2后停止工作

我将我的nginx服务器从0.7.x升级到1.0.2,并且复制了新的nginx服务器的旧configuration文件。 一切工作正常,除了if-指令。 我在旧的configuration文件中有以下的代码块,似乎没有与最新的nginx版本。 location /myapp { if (!-e $request_filename) { rewrite ^/myapp/(.*)$ /myapp/index.php?q=$1 last; break; } root /var/www; index index.php index.html index.htm; } 任何想法有什么不对? PS:是的,我知道IfIsEvil和我尝试探索try_files,但我无法弄清楚如何传递只有部分的URI后myapp /作为传递inputURI到index.php像这样: try_files $uri index.php?q=$uri

每个虚拟主机使用通配符子域中的mod_rewrite

::编辑:: 如何设置通配符子域名,然后重写地址? 目录结构 /var/www/domain.com // .htaccess with rewrite rules is placed here /var/www/domain.com/_admin /var/www/domain.com/_admin/tst /var/www/domain.com/_files /var/www/domain.com/_mysql 的.htaccess RewriteCond %{HTTP_HOST} ^(admin|files|mysql)\.domain\.com$ [NC] RewriteCond %{REQUEST_URI} !^/_(admin|files|mysql)/ [NC] RewriteRule ^(.*)$ /_%1/$1 [L] 当您请求http://admin.domain.com/tst ,地址被重写为http://admin.domain.com/_admin/tst 如何解决这个/_admin被隐藏?

dynamic重写使用$ 1,%1,%2等

如何使用$ 1,%1,%2等进行更复杂和dynamic的重写 我试图做一个更dynamic的重写(有很多domians指向同一个服务器/站点) # put 'www' as subdomain if none is given RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+)$ [NC] RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301] # rewrite subdomains RewriteCond %{HTTP_HOST} ^(admin|files|imap|mysql)\.[^\.]+\.[^\.]+$ [NC] RewriteCond %{REQUEST_URI} !^/_(admin|files|imap|mysql)/ [NC] RewriteRule ^(.*)$ /_%1/$1 [L] # redirect to subdomain RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ [NC] RewriteCond %{REQUEST_URI} ^/_([^/]*)/ [NC] RewriteRule ^(.*)$ http://%1.domain.com/ [L,R=301] # rewrite 'secure' subdomain […]

htaccess:无法检查dynamic文件path的存在!

我已经写了一个dynamic的缩略图创build者的htaccess文件,看看是否存在请求的文件,如果不发送用户到PHP页面来创build它。 我的htaccess文件如下所示: # Check the formatting (this works) RewriteCond %{SCRIPT_FILENAME}%{QUERY_STRING} /([a-zA-Z0-9-]+).(jpg|gif|png)w=([0-9]+)&h=([0-9]+)(&c=(true|false)) # Only forward to thumbnail.php if file doesn't exist #RewriteCond %{REQUEST_FILENAME} !-f #this works but not for the correct filename! RewriteCond %1-%2-%3-%4-%6.jpg !-f # Doesn't work!!! # If file doesn't exist, send here: (this works) RewriteRule ^.*$ thumbnail.php?file_name=%1&type=%2&w=%3&h=%4&c=%6 我检查文件的存在似乎不工作,但是…使用%{REQUEST_FILENAME}的旧版本的作品,但这不是我需要检查的正确的文件名。 我已经validation了新文件%1-%2-%3-%4-%6.jpg具有正确的输出,但不触发条件! 基于以下url: this-is-the-image-name.gif?w=200&h=100&c=true htaccess文件应该检查​​这个文件是否存在: this-is-the-image-name-gif-200-100-true.jpg […]

mod_rewrite和VirtualHosts:如何redirect1站点,但保留其他?

我在一个专用的CentOS 5.6服务器上托pipe4个虚拟主机: # rpm -qa|grep http httpd-2.2.3-45.el5.centos.1 其中一个是我的Drupal 7.2站点,另一个是持有属于我妻子的静态文本和照片 – 这里是httpd.conf的摘录: <VirtualHost 85.214.19.116:80> DocumentRoot /var/www/html/preferans.de ServerName preferans.de ServerAlias preferans.de *.preferans.de ErrorLog logs/preferans.de/error_log CustomLog logs/preferans.de/access_log common <IfModule mod_rewrite.c> <Directory "/var/www/html/preferans.de"> RewriteEngine on # needed by Drupal 7 for "clean URLs" RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^ index.php [L] </Directory> </IfModule> </VirtualHost> […]