Articles of mod rewrite

Apache重写 – >我不知道为什么这些规则不工作

我正在运行Apache,CentOS 6。 我有一组url,如果他们被击中,我希望用户指向的index.php 我不明白为什么这些规则不起作用。 谁能解释一下? 更新:新规则集 RewriteCond %{REQUEST_URI} ^/faculty/gray(/)?$ [NC,OR] RewriteCond %{REQUEST_URI} ^/includes(/)?$ [NC,OR] RewriteCond %{REQUEST_URI} ^/images(/)?$ [NC] RewriteRule ^(.*)$ index.php [R,L]

apache – mod_rewrite + mod_proxy在分期工作,不在生产中工作(忽略选项)

我在我的Apache虚拟主机中设置了一个redirect服务,这个虚拟主机服务于几个子域名 – 称为a.example.com和b.example.com – 在rails应用上提供ruby服务。 在我的虚拟主机configuration文件,我有这个规则: rewriteEngine on rewriteRule proxy/(.+)$ http://news.example.com/$1 [P] 这个想法是,我可以做http://a.example.com/proxy/news/a并获得http://news.example.com/news/a的内容,但在同一个子域,所以阿贾克斯doesn不认为我的阿贾克斯请求是跨域 – 关于这个问题的更多信息 。 问题是,虽然它在我的临时环境中工作得很好,但它不在生产中! 两台服务器都是Ubuntu服务器10.04。 Apache来自标准的ubuntu软件仓库,使用apt-get install 。 我已经做了整个/ etc / apache2 /目录的差异,唯一的区别是服务器名称。 如果我把最后一个选项改为[L],我得到一个redirect,所以这让我觉得mod_rewrite正在工作。 它只是不会与mod_proxy交谈。 通过查看日志( /var/log/apache2和rails日志),生产中的重写规则似乎被忽略 – 日志完全相同,就好像它不在那里一样。 我怎样才能debugging呢? 我可以强制Apache给我更多的信息,当我访问/proxy时为什么不执行这个特定的规则?

Lighttpd Mod-Rewrite Rule Matching All Subdomains

我正在使用lighttpd web服务器和mod_write并有一个简单的主机匹配expression式: $HTTP["host"] =~ "domain\.com$" { } 问题是这是匹配test.domain.com以及。 我如何修改expression式只匹配http://domain.com,但不是任何子域,如test.domain.com? 谢谢。

用mod_rewrite强制SSL

我有下面的声明,它完美的工作redirect所有请求“WWW”:80强制浏览器到相同的位置:443 RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^/(.*)$ https://www.mydomain.com/$1 [R=301,L] 但是,我想要做的是,无论https://和.mydomain.com之间的什么 – 在这种情况下,www,但它可以是任何东西,如“www2”或“dev”等 – 我想URL简单地转换为它的SSL等效。 我是新来的mod_rewrite,所以我正在寻找甚至可能的假设子域可以是任何可变长度的字符? 在此先感谢您的帮助。

位置指令覆盖mod_wsgi脚本别名安装

所以我受阻 我有一个使用Django的Web应用程序,我使用mod_wsgi将其与Apache整合。 但是,另一个人在代理另一台服务器的同一台机器上有指令。 Apache的configuration大致是: 我的应用程序 WSGIScriptAlias /stuff /foo/foo/wsgi.py WSGIPythonPath /foo <Directory /foo/foo> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory> 他的应用程序 <Location "/"> Order Allow,Deny AllowFromAll ProxyPass myotherserver ProxyPassReverse myotherserver </Location> 不幸的是,他的位置指令覆盖了我的脚本指令,并且所有我对http / www.bar.com / stuff的请求最终都不经过wsgi脚本就被转发到http://www.myotherserver.com/stuff 。 我如何向django提出请求/直接提交给Django而不是代理通行证,而不会搞乱他的代码或在另一个服务器上拆分他的实现? 我试过了 RewriteEngine on RewriteCond %{REQUEST_URI} ^!/stuff RewriteRule ^.*$ /bat/$1 [NC,PT] <Location "/bat"> Order Allow,Deny AllowFromAll ProxyPass […]

与查询string替代的Mod-proxy?

我目前正在尝试使用mod_proxy在另一台服务器上进行search请求。 远程服务器请求的结构如下: http://path.to.remote/search.php?key=MYKEY&term=SEARCHTERM 为了模糊我的访问密钥,我希望在我的虚拟主机定义中包含authentication。 由于键必须作为查询string值传递,所以我认为这将是简单的: ProxyPass /lookup/t/ http://path.to.remote/search.php?key=MYKEY&term= 我的url看起来像什么地方 http://localhost/lookup/t/term=SEARCHTERM 我很快发现,ProxyPass会在目标URL上执行强制性字符转义,导致我的URL无法使用。 我发现了很多有类似问题的人,主要是以前编码过的字符,并且ProxyPass的URL编码是不可避免的。 我发现了一些build议,我应该使用mod_rewrite为我组装代理请求,但我不知道如何做到这一点。 我的虚拟主机定义中的规则看起来像这样: RewriteEngine On RewriteCond %{REQUEST_URI} !^/lookup/t/ RewriteRule ^/lookup/t/$ http://path.to.remote/search.php?key=MYKEY&term=$1 我没有mod_rewrite很多的经验,我的正则expression式技能不是很好,所以我希望有人能够解释我将如何重写我的URL,以及如何通过mod_proxy根据需要漏斗。 我正确的想我需要使用重写来组装查询string,如下所示: Http://localhost/lookup/t/term=SEARCHTERM Http://localhost/lookup/t/?key=MYKEY&term=SEARCHTERM 然后用mod代理去 /lookup/t/ 至 http://path.to.remote/search.php

URL查询string导致布局中断

我有一个基于Apache服务器的WordPress的网站,重写URL是“漂亮”。 当我在URL中包含一个查询参数时,网站会中断。 所以: http://mysite.com 工作正常,但: http://mysite.com/?anything 不加载页面内容,但无法加载我在主页上使用的一些插件。 如果你能解释为什么会发生这种情况,我很乐意听到。 否则,我只想完全剥离查询参数,以便请求: http://mysite.com/?anything 会像请求一样行事: http://mysite.com 通过redirect或通过简单地删除查询string。 这是我当前的.htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Handle redirection from https to http RewriteCond %{HTTPS} =on RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301] # End https to http redirection RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{QUERY_STRING} […]

Apache2:使用RewriteCond&RewriteRule在查询string中匹配重音字符的问题

在计划将URL从查询string格式移至基于数字的格式的网站上工作。 存在许多URL,其中有非转义的重音和类似的UTF8字符。 问题? 我似乎无法让Apache2正确匹配重音字符并重写。 我在Apache2configuration中完成了这一切。 例如,这个URL: http://great.website.example.com/?place=cafe 按照预期的这个Apache2 RewriteRule设置工作: RewriteCond %{QUERY_STRING} ^(place|location)=cafe RewriteRule ^/find/$ /find/1234? [L,R=301] 现在看看这个url。 请注意重音符号: http://great.website.example.com/?place=café 为什么这个URL不能用于下面的Apache2 RewriteRule设置: RewriteCond %{QUERY_STRING} ^(place|location)=café RewriteRule ^/find/$ /find/1234? [L,R=301] 这两个规则都应该将URL重写为以下内容: http://great.website.example.com/find/1234 但是带有重音符号的例子根本不起作用。 也许通配符会起作用,但我似乎无法得到这个工作。

请求超过了10个内部redirect的限制

所以这里是错误 [Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php [Mon Sep 30 00:09:53 2013] [debug] […]

Apache的mod_rewritevariables主机名与一个redirect?

我有一个testing服务器(webtest.example.com)和一个在线服务器(www.example.com)。 我也有example.org,example.net等我希望那些redirect到example.com。 我也想要任何非www条目redirect到www。 基本上,我只想知道是否有更高效(即更less线路)的方式来处理这个问题? RewriteCond %{HTTP_HOST} !^www\.example\.com$ RewriteCond %{HTTP_HOST} !^webtest\.example RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^webtest\.example\.com$ RewriteCond %{HTTP_HOST} ^webtest\.example RewriteRule ^(.*)$ http://webtest.example.com%{REQUEST_URI} [L,R=301] 似乎也许会有一种方法将2个块合并成一个块。