Articles of mod rewrite

Apache2 mod_rewrite,处理URL末尾的可选“/”

我正在尝试托pipe一个自定义页面,将其设置为我的服务器上的主页。 页面的真实path是example.com/start.html 。 但是,我不希望在我的主页中使用这个丑陋的URL,所以我试图让path是example.com/start/ 。 我的.htaccess文件内容是: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^start\/?$ start.html [NC,L] </IfModule> 这会使example.com/start正确redirect,但是example.com/start/会导致404错误(强调URL最末尾的斜线)。 我得到的错误是: The requested URL /start.html/ was not found on this server. 我相信我在RewriteRule中的正则expression式是正确的(它应该接受“开始”或“开始/”,所以我不确定问题是什么。 我将不胜感激这个问题的任何帮助。

Apache使用“全部捕获”规则重写多个命名虚拟主机的规则

我有一个redirect的Apache服务器,我设置了约30个域名。 我想要所有的请求被redirect到主服务器,除了一个域。 基本上任何域到这个服务器被转发到www.maindomain.com; 但是,我想要domain234.com和www.domain234.com转发到https://www.site.com 我发现了这个回应,试了一下却没有成功: <VirtualHost _default_:80> RewriteCond %{HTTP_HOST} ^(.*)$ RewriteRule ^(.*)$ https://www.maindomain.com [R=permanent,L] </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName domain1.com ServerAlias www.domain1.com ServerAlias domain2.biz ServerAlias domain3.info RewriteEngine on RewriteCond (.*) https://site.foo.com [R=301,L] </VirtualHost> 任何人有我的build议来解决这个问题?

将htaccess重写规则转换为nginx

通过search互联网“转换htaccess的nginx规则”我想出了anilcetin和winginx .htaccess的nginx转换器,我怀疑它不能正确输出我所需要的。 以下哪项更准确? 你能帮我解决这个问题吗? 这是我想要转换为Nginx的.htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ %{ENV:BASE} index.php [QSA,L] 以下是转换器的输出。 Anilcetin if (!-f $request_filename){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ #ignored: "-" thing used or unknown variable in regex/rew } Winginx # nginx configuration location / { if (!-e $request_filename){ rewrite ^(.*)$ /$env_base index.php break; } }

URL重写一个特定的目录

我想在接收到一个不是文件的请求时重写URL,或者是根目录subdir或者根本不是一个目录。 例如( !file )&&(( subdir )|( !directory )) 这是我的.htaccess : RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} ^/(subdir|subdir/.*).*$ [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+) index.php?request=$1 [QSA] 除了subdir以外,它可以在任何地方使用 捕获subdir的重写条件不起作用,它的行为就好像根本没有重写规则。 我在这里做错了什么?

当入站请求URL是HTTP时,可以mod_rewrite roxy到HTTPS url?

我有一个主机(IIS6,通过一个名为Micronovae的Windows运行mod_rewrite的实现,运行良好),它有一个http://some.host.com网站 我还有另一台主机(位于微软Azure),在https://secure.otherhost.com有一个站点 目前我有一个mod_rewrite规则集,因此: #visitor to some.host.com is transparently proxied to new site at secure.otherhost.com ReWriteCond %{HTTP_HOST} some\.host\.com [NC] ReWriteRule (.*) https://secure.otherhost.com$1 [P,L,QSA] 我知道规则的工作原理(虽然我设置了日志logging选项,但是事情似乎没有logging到它应该在的地方),因为如果我将它作为[R]规则而不是[P]规则,那么浏览器会收到redirect并转到HTTPS secure.otherhost.com就好了 但是..如果我启用[P] roxy模式,而我尝试去http://some.host.com只是得到一个404错误 任何人都可以给我一个线索? 服务器可以与外部服务器进行HTTPS对话,然后通过HTTP将结果返回给我的客户端浏览器?

Apache2反向代理 – 不同的处理或url

我正在努力与反向代理configuration和具体的重写/ proxypass取决于URLpath。 SZENARIO: DMZ中的反向代理 SSL在反向代理上结束 请求应通过http传递给内部服务器 HTTP需要重写为HTTPS 在html hrefs中,像“/system/js/abc.js” 我目前的configuration: <VirtualHost *:80> ServerName media.customer.com RewriteEngine On RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$ RewriteRule ^(.*)$ https://media.customer.com$1 [R=301,L] </VirtualHost> <VirtualHost *:443> ServerName media.customer.com DocumentRoot /var/www/customer.com/ SSLEngine On SSLCertificateKeyFile /etc/apache2/certs/server.key SSLCertificateFile /etc/apache2/certs/server.crt ProxyRequests Off ProxyPass / http://serverName/ ProxyPassReverse / http://serverName/ ProxyHTMLEnable On ProxyHTMLURLMap http://serverName/ / </VirtualHost> 这不会是一个大问题,但我们需要得到以下规则工作: 只有base-url“Http:// serverName”路由到http:// serverName / […]

如何通过openshift为单个页面应用程序提供服务

我尝试在openshift上部署单个页面的应用程序。 在openshift所有的静态内容必须在wsgi /静态目录,但我显然想从我的静态index.html从根。 每个尝试在wsgi / dir中使用.htaccess来做到这一点似乎都不起作用。 这是正确的方式吗? 如果是的话,我该如何debugging呢? 是否有任何openshift htaccess的具体规则?

为什么RewriteEngine On之后的所有内容都被忽略?

所以我试图让我的新网站mod_rewrite工作。 几年前,我已经成功地使用了mod_rewrite,但这次在'RewriteEngine On'之后没有一个单独的命令。 我在我的本地Apache 2.2上获得与我的Web主机服务器上完全相同的效果,所以不是服务器没有configuration为mod_rewrite。 我的本地机器运行Windows,而远程服务器是Linux,所以它们是相当独立的系统。 以下是我为本地主机检查的内容: httpd.conf中的'LoadModule rewrite_module'行没有用# 我有'选项索引FollowSymLinks包括'在我的httpd.conf为我的HTML目录 我也有'AllowOverride All'的选项旁边。 正在访问我网站根目录中的.htaccess文件。 把废话在第一行让我一个内部服务器错误,删除它把它拿走 把'RewriteEngine奶酪'作为第一行让我在我的error.log中说'RewriteEngine必须打开或closures',所以它似乎已经准备好做一些重写… 但。 RewriteEngine On后没有input任何结果! 我可以在那里写废话,没有错误信息。 我已经把很多命令作为一个testing,但即使这个.htaccess文件也没有做任何事情: RewriteEngine On RewriteRule ^.*$ test.html [R] 这应该重写每一个页面我去成为test.html不应该呢? 然而,什么都没有发生 – 如果我去hello.html,我只是得到一个网页,说没有findhello.html。 请有人提出一个build议,接下来要做什么?

mod_rewritedate子文件夹不工作

我有一个奇怪的问题,我感到困惑。 我会和那个正则expression式的前奏不是我的强项。 我需要社区的反馈来实现这一目标。 如果我有以下url: http://example.com/2015-03-25/ 我想通过一个PHP文件运行这些。 这条规则对于下面的mod_rewrite很有效: RewriteRule ^/?([0-9]){4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/(.*)$ show_page.php?page=$3 [NC,L] 但是我想把文件夹移到: http://example.com/my_pages/2015-03-25/ 此规则不起作用: RewriteRule ^/my_pages/?([0-9]){4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/(.*)$ show_page.php?page=$3 [NC,L] 此规则也不起作用: RewriteRule ^my_pages/?([0-9]){4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/(.*)$ show_page.php?page=$3 [NC,L] 我在这里错过了什么? 社区的帮助非常感谢。 UPDATE! 这是我所做的解决这个问题: RewriteRule ^my_pages\/([0-9]){4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/(.*)$ show_page.php?page=$3 [NC,L] 与 RewriteRule ^/my_pages/?([0-9]){4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/(.*)$ show_page.php?page=$3 [NC,L] 奇怪的是,在Apache 2.4上,正确的语法实际上是。 RewriteRule ^my_pages/?([0-9]){4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/(.*)$ show_page.php?page=$3 [NC,L]

Apache .htaccess规则中的特殊nginx热链接保护转换

在Apache中,我有以下反向重写规则,我希望在nginx中有这个规则。 我看到cookie或引用规则示例。 但是两者都没有结合,所以我不知道如何去做这件事。 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ [OR] RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?domain\.com.*$ [NC] RewriteCond %{HTTP_COOKIE} !^.*_.*$ RewriteRule \.(flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js|htc|woff|otf|eot|ttf)$ – [F,NS,L] </IfModule> 这是一个轻松的规则,允许空的引用,如果与一个已知的cookie发送(例如_ )。 但是当使用无效的域引用者时,它将拒绝没有设置cookie的访问。