Articles of mod rewrite

Apache嵌套的虚拟主机

我有一个Apache服务器中的两个虚拟主机,我想做的事情,但我不知道是否有可能。 事情是我有主要的应用程序开发和ruby和博客是在wordpress。 所以现在我有这样的东西: example.com和blog.example.com 我想要做的是,对www.example.com/blog的所有请求都由blog.example.com提供,但是不会执行redirect(即,我不希望用户看到URL中的更改) 我到目前为止所尝试的是在VirtualHost中做一个代理: <Location /blog> ProxyPassReverse http://blog.example.com ProxyPassReverse http://blog.example.com:80 RewriteEngine On RewriteRule blog/(.*)$ http://blog.example.com/$1 [QSA,P,L] </Location> 它可以工作,但是一旦我在另一个应用程序中,所有链接都在blog.example.com中,而不是在example.com/blog中。 你知道这个解决方法吗? 感谢您的帮助。

.htaccess中的mod_rewrite导致头文件不被应用 – 为什么?

摘自httpd.conf <VirtualHost *:80>部分(目标:为所有 JavaScript文件设置Cache-Control ): <LocationMatch "\.js"> Header set Cache-Control "max-age=290304000, public" </LocationMatch> .htaccess (Symfony PHP框架的一部分): Options +FollowSymLinks +ExecCGI <IfModule mod_rewrite.c> RewriteEngine On # we check if the .html version is here (caching) RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f # no, so we redirect to our front web controller RewriteRule […]

使用mod_rewrite / mod_proxy更改Set-Cookie头

我有一堆使用HTTPS的CGI脚本。 他们只能在内联网上,而不能从外部访问。 他们使用“安全”属性设置cookie,以便只能通过HTTPS发送。 对于其中一个脚本,也有一个反向代理,不幸的是使用普通的HTTP。 当我的CGI脚本有一个安全的cookie来响应时,它不会通过HTTP传递(毕竟,这是属性的用途)。 然而,我需要这个规则的例外。 是否有可能使用mod_rewrite / mod_proxy或类似的东西来改变来自我的CGI脚本的响应中的Set-Cookie头并删除Secure ,这样cookie可以通过不安全的HTTP连接传回给用户? 我明白,这首先破坏了Secure的目的,但我需要这个作为临时工作。 我search了网页,发现如何使用mod_rewrite添加一个Set-Cookie头,我也发现了如何从cookie头中获取来自客户端的cookie 。 我还没有find的是如何提取在我正在代理的脚本的响应中收到的Set-Cookie头。 那可能吗? 我该怎么做?

如何将path映射到Apache中的path.html?

我的旧网站是dynamic的,所有的固定链接都是这种forms: http://wangling.me/2000/01/file或http://wangling.me/2000/01/file/ 现在我刚刚重build我的网站与静态HTML文件,所以永久链接变成: http://wangling.me/2000/01/file.html 所以我想把旧的永久链接映射到新的永久链接上。 我在/etc/apache2/sites-enabled/wangling.me写了这个: <VirtualHost *:80> ServerAdmin xxx ServerName wangling.me ServerAlias *.wangling.me DocumentRoot doc_root RewriteEngine On RewriteCond /$1 !-d RewriteCond /$1 !-f RewriteCond /$1.html -f RewriteRule ^/([^.]+?)/*$ /$1.html </VirtualHost> 但它不起作用。 这里是相关的日志: [Sat Jan 19 00:49:01 2013] [error] [client 24.12.163.253]文件不存在:doc_root / 2012/05 / xyz 所以似乎没有使用RewriteRule 。 我知道我的configuration一定有什么问题,因为我甚至不知道RewriteRule Pattern Substitution究竟是什么RewriteRule Pattern Substitution 。 是绝对URL( http://wangling.me/2012/05/xyz […]

使用mod_proxy_http和mod_rewrite的时候保护Apache

我们有一个Apache服务器,作为运行在不同端口上的应用程序的代理。 例如: domain.com/app1/service1 > localhost:101 domain.com/app1/service2 > localhost:102 domain.com/app2/service1 > localhost:201 确定应用程序端口的规则相当复杂,所以我使用一个脚本来使用mod_rewrite来做到这一点: RewriteEngine On RewriteMap mapper prg:/foler/rewriteUrl.sh RewriteRule ^(.*)$ ${mapper:%{REQUEST_URI}} [P] 我遇到的问题是查看日志,从其他网站获取内容的机器人有很多请求。 我testing了是否可以从其他服务器代理内容,我可以: telnet domain.com 80 GET http://www.yahoo.com/ HTTP/1.1 Host: www.yahoo.com 在这里,我从雅虎获得内容,这意味着任何人都可以连接到我的服务器,并开始向其他服务器发送请求。 我已经看到,Apachebuild议如下所述保护您的代理: http://httpd.apache.org/docs/trunk/mod/mod_proxy.html#access 但问题是,我不知道什么IP将使用我的服务器在高级,所以我的问题是如何解决这个问题,同时任何人都可以向我的应用程序请求? 一些额外的信息: 我所有的应用程序都与我的Apache服务器在同一台机器上 如果我需要移动我的应用程序到不同的服务器,他们将仍然在我的Intrantet 我有mod_proxy,mod_proxy_http和mod_rewrite启用 谢谢

Apache重写在FreeBSD下工作,不在CentOS下

我有5台运行FreeBSD 9.2的生产服务器,但是我们正在计划转换到CentOS。 正因为如此,我正在尝试使用CentOS 6.6来设置一些虚拟机来模拟我们的生产服务器环境。 我已经设置了一切,它的效果很好,保存一个重写规则。 <Directory /var/www/html/www/trunk/amapi> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </Directory> <Directory /var/www/html/www/trunk/amapi/public> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] </Directory> <Directory /var/www/html/www/trunk> RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /.*start\.php RewriteRule ^start.php/?(.*)$ $1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ start.php/$1?%{QUERY_STRING} [L] </Directory> 前两个重写规则适用于使用Phalcon的后端API,并且在两种环境中都可以很好地工作。 […]

我可以使用mod_alias的“Redirect”来使用Apachevariables,而不是使用mod_rewrite吗?

Apache HTTP服务器的mod_alias提供了Redirect指令,这对于简单的redirect非常mod_alias ,如下所示: # Redirect login to https Redirect permanent /login https://www.example.org/login 虽然许多pipe理员使用mod_rewrite进行redirect,但在不使用mod_rewrite的Apache文档中,通常build议mod_alias优先于mod_rewrite 。 我想更多地使用mod_alias 。 我可以使用Redirect与Apachevariables ,如ServerName ? 例如,要强制通过HTTPS提供某些内容,我想要做这样的事情: Redirect permanent /login https://%{SERVER_NAME}/login Redirect permanent /special-project-1 https://%{SERVER_NAME}/special-project-1 Redirect permanent /special-project-2 https://%{SERVER_NAME}/special-project-2 这些都不起作用,并且在响应中打印了string%{SERVER_NAME} : host% curl http://www.example.org/login … 302 Found The document has moved <a href="https://%{SERVER_NAME}/login">here</a>. mod_alias指令允许Apachevariables吗? variables是否可以使用不同的语法?

重写/限制在Apache中的特定域名

我们有https://example1.com/login和example2.com/login从同一个Apache服务器(2.2.22)托pipe。 我想限制/login example1.com 。 example1.com/login – > 404(最好)或403 example2.com/login – >login页面 我试过了 <Location /login> Order Deny,Allow Deny from example1.com Allow from example2.com </Location> 它禁用/login example1.com和example2.com 。 我可以限制example1.com吗?

重写导致现有目录上的无限301redirect循环

我经历了在这里find的问题/解决scheme,尝试了很多方法(包括[L]指令),但没有什么真正的诀窍。 情况概览 Debian通过nginx运行Apache 2.2代理 目标 将所有内容redirect到/index.php并确保总是有一个斜杠。 从规则中排除以下目录: js_static 媒体 排除规则中的所有.css文件。 问题 当我打电话给www.url.com/js_static时,Apache / nginx会导致301redirect循环。 (问题也出现在跟踪斜线 – 没有区别) 当前的解决scheme nginx是这样configuration的: gzip_proxied any; rewrite ^/(.*)/$ /$1; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:AES256+EDH'; Apache是​​这样configuration的: RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !^.+\.(css) RewriteCond %{REQUEST_URI} !^.+js_static RewriteCond %{REQUEST_URI} !^.+media RewriteRule ^(.*)$ /index.php/$1 AllowEncodedSlashes On 我没有看到问题出在哪里。 我有一个理论是nginx / apache重写的组合会产生问题,所以我摆弄的configuration,但无济于事,不幸的是。 有人可以在这里找出问题吗?

我怎样才能让Apache在两个单独的目录中看到一个共同的url? 后续问题

这是我之前在这个网站上的问题的一个后续问题。 也许我应该指出,Apache服务器运行在Windows系统上,不知道是否重要。 我的问题如下: 我有2个驱动器J:和K :,都有一个目录testing( J:/ test /和K:/ test / ) J:/ test /包含文件pink.html K:/ test /包含文件red.html和blue.html 我想访问J:/ test /和K:/ test /中的所有文件,并使用相同的url: HTTP://localhost/test/pink.html HTTP://localhost/test/blue.html HTTP://localhost/test/red.html 这是我的httpd.conf文件的摘录: Alias /test/ "J:/test/" Alias /test2/ "K:/test/" <Directory "J:/test/"> Order allow,deny Allow from all Options All MultiViews AllowOverride None RewriteEngine on RewriteCond /test/%(REQUEST_FILENAME) !-f #if we can't find the file […]