Articles of mod rewrite

Apache什么时候重新读取.htaccess文件的更新?

我有一个托pipe服务器。 当我更新.htaccess时,更新的规则是否立即生效? 我知道托pipe人可以做他们想做的事,不知道这个特定托pipe人的特定政策是不可能知道的。 但在正常情况下,如果我更新.htaccess,Apache是​​否立即重新读取? 还是有什么我可以告诉Apache重新读取它? 或者是什么?

“redirect永久”与mod_rewrite RewriteRule之间的区别

这是一个Apache httpd 2.2服务器。 我们要求通过HTTPSencryption这个networking服务器。 当Web客户端访问我的网站http://www.example.org/ $ foo(端口80)时,我想将他们的请求redirect到https://www.example.org/ $ foo的HTTPSencryption网站。 似乎有两种常见的方法来做到这一点: 第一种方法使用mod_alias中的“ Redirect ”指令: <VirtualHost *:80> Redirect permanent / https://www.example.org/ </VirtualHost> 第二种方法使用mod_rewrite: <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </VirtualHost> “redirect永久”和mod_rewrite节之间有什么区别? 一个比另一个更好吗?

具有特殊字符的Apacheurl/文件名

我有这个url: http://domain.com/wp-content/uploads/2012/10/Hvilke-vilkår-følger-med-når-du-bestiller-nyt-bredbånd.png 如果我ftp / ssh或只是浏览到该文件夹​​(Apache索引function),我看到的文件 Hvilke-vilkår – 福尔杰-MED-NAR-DU-bestiller-NYT-bredbånd.png 如果我点击从apache索引的链接,我可以看到该文件,但是,如果我复制的URL,并尝试直接浏览它,我得到的错误: 在此服务器上找不到所请求的URL/wp-content/uploads/2012/10/Hvilke-vilk?r-følger-med-nÃ¥r-du-bestiller-nyt-bredbÃ?nd.png。 另外我的错误日志说: 文件不存在:/ wp-content / uploads / 2012/10 / Hvilke-vilk \ xc3 \ xa5r-f \ xc3 \ xb8lger-med-n \ xc3 \ xa5r-du-bestiller-nyt-bredb \ xc3 \ xa5nd。 PNG

mod_rewrite REQUEST_FILENAME不包含绝对path

我在testing是否存在%{REQUEST_FILENAME}的mod_rewrite RewriteCond条目中遇到了文件testing操作的问题。 看来,而不是%{REQUEST_FILENAME}是一个绝对path,我得到一个根源于DocumentRoot的path。 组态 我在我的apache 2.2.9configuration中有一个<VirtualHost>块: RewriteEngine on RewriteLog /tmp/rewrite.log RewriteLogLevel 5 #push virtually everything through our dispatcher script RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/([^/]*)/?([^/]*) /dispatch.php?_c=$1&_m=$2 [qsa,L] 诊断试图 该规则是通过脚本为不存在的文件或目录路由请求的常见惯用语。 麻烦的是,即使文件存在,它也会被触发。 如果我删除规则,我可以请求正常的文件就好了。 但是随着规则的到来,这些请求被定向到dispatch.php 重写日志跟踪 这是我在rewrite.log中看到的 init rewrite engine with requested uri /test.txt applying pattern '^/([^/]*)/?([^/]*)' to uri '/test.txt' RewriteCond: input='/test.txt' pattern='!-f' => matched RewriteCond: […]

在反向代理中重写Apache URL

我在一个Karaf托pipe的应用程序(Apache和Karaf在不同的服务器上)前部署Apache。 我希望Apache可以作为反向代理运行,也可以隐藏部分URL。 直接从应用程序服务器获取应用程序login页面的URL是http://app-server:8181/jellyfish 。 页面由在Karaf内运行的Jetty实例提供服务。 当然,除了反向代理服务器以外,这种行为通常会被防火墙阻止。 在防火墙closures的情况下,如果您点击此URL,Jetty将加载login页面。 浏览器的地址栏正确地更改为http://app-server:8181/jellyfish/login?0 ,一切正常。 我想要的是http://web-server (即从根目录)映射到应用程序服务器上的Jetty与应用程序( jellyfish )的名称压制。 例如,浏览器将更改为在地址栏中显示http://web-server/login?0 ,所有后续的URL和内容将与Web服务器的域一起提供,并且不会出现jellyfish混乱。 我可以使用下面的configuration(snippet)让Apache作为一个简单的反向代理来运行: ProxyPass /jellyfish http://app-server:8181/jellyfish ProxyPassReverse / http://app-server:8181/ …但这需要浏览器的URL包含jellyfish和去根URL( http://web-server )给出了404 Not Found。 我花了很多时间试图使用mod_rewrite和没有[P]标志来解决这个问题,但没有成功。 然后我尝试了ProxyPassMatch指令,但我似乎无法得到相当正确的。 这是当前的configuration,正如加载到Web服务器上的/etc/apache2/sites-available/ 。 请注意,有一个本地托pipe的图像目录。 我也保留了mod_rewrite代理漏洞保护,并且压制了一些伪造的错误mod_security规则。 <VirtualHost *:80> ServerAdmin admin@drummer-server ServerName drummer-server ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /images/ "/var/www/images/" RewriteEngine On RewriteCond %{REQUEST_URI} !^$ RewriteCond […]

标题集访问控制允许来源不与mod_rewrite + mod_jk工作

我在SF上的第一个问题,所以请原谅我,如果我设法博克的职位。 🙂 无论如何,我在我的一台机器上使用了mod_rewrite,并且有一条简单的规则,可以在另一台机器上redirect到一个webapp。 我也在这两台机器上设置标题“Access-Control-Allow-Origin”。 问题是当我重写规则时,我放弃了“Access-Control-Allow-Origin”标题设置。 以下是第一台机器的Apacheconfiguration示例: NameVirtualHost 10.0.0.2:80 <VirtualHost 10.0.0.2:80> DocumentRoot /var/www/host.example.com ServerName host.example.com JkMount /webapp/* jkworker Header set Access-Control-Allow-Origin "*" RewriteEngine on RewriteRule ^/otherhost http://otherhost.example.com/webapp [R,L] </VirtualHost> 下面是第二个Apacheconfiguration的例子: NameVirtualHost 10.0.1.2:80 <VirtualHost 10.0.1.2:80> DocumentRoot /var/www/otherhost.example.com ServerName otherhost.example.com JkMount /webapp/* jkworker Header set Access-Control-Allow-Origin "*" </VirtualHost> 当我点击host.example.com我们看到标题已设置: $ curl -i http://host.example.com/ HTTP/1.1 302 Moved Temporarily Server: […]

HTTP请求上的Apache mod_substitute到反向代理主机

我有以下设置: 局域网上的打印机#1 打印机#2在LAN上 互联网面临的server-external-ip Debian的Apache 2.2 Web服务器,我想用作IPP网关的两台打印机 这两台打印机可以通过以下IPP URL访问(从LAN和Apache服务器): http://printer-1-local-ip/printer http://printer-2-local-ip/printer (打印机没有物理连接到Web服务器。) 我希望它们可以通过以下URL从Internet访问: http://server-external-ip/prn1 http://server-external-ip/prn2 IPP专门通过对打印机地址的HTTP请求来工作(即,整个打印过程通过POST请求在http:// printer-X-local-ip /打印机 URL处发生),所以我只需要redirect(即反向代理与Apache)上面的URL 1和2。 Apache正在服务其他内容,所以我不能用自定义程序(例如netcat或netsed)来replace它。 另外,由于打印机客户端只能够在端口80处到达服务器,因此我无法在其他端口上运行自定义程序。 然后我尝试了下面的Apacheconfiguration: RewriteRule ^/prn1$ http://printer-1-local-ip:80/printer [P] ProxyPassReverse /prn1 http://printer-1-local-ip 将Windows客户端连接到http:// server-external-ip / prn1 URL,反向代理就可以工作。 但是IPP协议还会向打印机(在POST-ed数据中)发送完整的设备URL。 这意味着打印机会收到http:// server-external-ip / prn1打印机的显式IPP请求,而不是其正确的地址( http:// printer-1-local-ip / printer )。 所以它拒绝连接。 我将这个条目添加到Windows客户端的HOST文件中: server-external-ip printer-dns-name 但它仍然不起作用,因为打印机收到仍然具有错误服务名称的http:// printer-dns-name / prn1的IPP请求(即, prn1而不是打印机 )。 […]

如何启用mod_rewrite详细logging

我正在尝试在trace3日志级别启用mod_rewrite详细日志logging, 如man 。 我把这一行放在我的conf : LogLevel alert rewrite:trace3 不过,我得到这个错误: / etc / apache2 / sites-enabled /“my_site”的第6行的语法错误:LogLevel带有一个参数,错误日志logging中的详细程度 我的Apache版本是:Apache / 2.2.17(Ubuntu) 这是从我的conf文件摘录: <VirtualHost 10.10.10.14:80> ServerName my_site <br> DocumentRoot "/data/website/php./web" <br> ErrorLog "/data/website/logs/error.log <br> CustomLog "/data/website/logs/access.log combined <br> LogLevel alert rewrite:trace3 <br> </VirtualHost> 请帮助我纠正LogLevel语句。 谢谢。

mod_rewrite中的相对replaceRewriteRule

我想创build一个mod_rewrite RewriteRule是独立于网页的安装位置。 我想在.htaccess文件中定义重写规则。 我们以此为例: RewriteEngine on RewriteRule ^(.*)\.html html.php 有了这个规则,我想把所有* .html请求映射到一个位于web根目录下的html.php脚本。 问题是,webroot的公共基础URL可能会改变。 所以Web根可以位于http://www.somewhere.tld/或http://www.somewhere.tld/的某个子目录中。 但在重写规则中使用相对path不起作用。 所以我必须写下其中的一个: /html.php (When web is located in root directory of the web) /foo/bar/html.php (When web is located in foo/bar sub directory) 或者我可以设置一个RewriteBase,但我根本不想configuration这个path。 我希望apache自动做正确的事情,所以我可以复制到一些目录的网页,它只是工作,而不告诉重写规则的网站位于。我怎样才能做到这一点?

使用mod_rewrite强制HTTPS,包括代理SSL

我有一台服务器从SSL端接负载平衡器获取一些stream量,在这种情况下,它通过端口80以http_x_forwarded_proto =“https” 我想要一个mod_rewrite规则,只允许直接的HTTPSstream量或转发的HTTPSstream量。 我到目前为止: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP:http_x_forwarded_proto} != https RewriteCond %{HTTP:http_x_forwarded_proto} != HTTPS RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 但我越来越 RewriteCond:坏标志分隔符 错误。 我需要纠正什么才能使这个工作,这是最好的方法?