Articles of 重写

Apache mod_rewrite在Internet Explorer中的怪异行为

我正在尝试为几个根域设置redirect。 首先,这是我的httpd-vhosts.conf文件中的代码: <VirtualHost *:80> ServerAdmin ****@example.com ServerName example.com ServerAlias example2.com RewriteEngine On RewriteCond %{HTTP_HOST} !^192\.168\.0\.1$ # This is our WAN IP RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE] </VirtualHost> 这样做是将example.com或example2.com的根域或www以外的任何主机redirect到www.example.com(2).com 我遇到问题的部分是RewriteRule本身。 $ 1应该与RewriteRule的模式相匹配,并将其添加到replace中。 例如:“ http://example.com/test.html ”应该重写为“ http://www.example.com/test.html ” 它适用于所有现代浏览器,除了IE8或IE9外(我没有testing其他IE版本)。 在IE中,这是有效的:“ http://example.com ”为“ http://www.example.com ” 在IE中,这是行不通的:“ http://example.com/test.html ”到“ http://www.example.com/test.html ” 有没有人有这种行为的解释? 我希望我已经解释得很好。 […]

IIS重写规则检查查询string,并添加它,如果它不存在

我正在尝试制作一个IIS URL重写规则,将URL参数附加到URL。 url参数是hssc 。 所以,任何通过服务器处理的url都需要这个参数。 请记住,有些url已经有自己的参数了,其他url不会,还有根url等等,有时需要添加?hssc=1或者&hssc= – 所以,如果我的url是这样: http://www.blah.com应该成为http://www.blah.com/?hssc=1 http://www.blah.com/index.html应成为http://www.blah.com/index.html?hssc=1 http://www.blah.com/?q=5应成为http://www.blah.com/q=5&hssc=1 http://www.blah.com/index.html?q=5应成为http://www.blah.com/index.html?q=5&hssc=1 http://www.blah.com/index.html?q=5&hssc=1应该单独留下 我也希望它的URL不应该被隐藏(如在后台在后台重写)。 我需要URL出现在URL中,所以当用户复制URL或书签时,参数就在那里。 我已经设置了匹配它的条件\&hssc|\?hssc – 现在我只需要一种方法来编写URL,这样它就会出现并保留已经存在的原始URL的一部分。

更改iis7上的默认端口后,Url重写停止工作

我已经使用msdeploy工具将IIS6 webserver 2003网站迁移到IIS7 webserver 2008。 应用程序池设置通过"Enable 32-bit Applications=true", "Managed_Pipeline_Mode=Classic","Identity=NetworkService" Framework=v1.1/2.0进行更改。 所有的网站在默认端口上工作正常,以及从iis6迁移的url重写。 当我通过更改绑定启动除默认端口以外的其他端口上的Web服务器时,URL重写将停止工作,并在日志中获得404错误。 我想我不必更改处理程序映射因为我在经典模式下运行它。 我怎样才能解决这个问题?

nginx将子域重写为文件作为variables

你如何获得子域作为一个variables添加重写? 你好 .example.com应该去example.com/user.php?u= 你好,但仍然显示为只是你好 .example.com 我目前在做http://example.com/users/ hello,但想为用户提供Tumblr风格的域名。 rewrite ^/users/(.*)$ /user.php?u=$1 last; 另外,如果在子域hello.example.com/settings/之后有像/ settings /这样的页面,我需要重写一个settings.php

在nginx中有两次“位置/ {}”块

对于我们所有的网站,我们都有一个包含以下内容的包含文件: location / { try_files $uri /index.php?$query_string; } 对于单个站点,我们希望将所有来自mysite.com/的请求redirect到mysite.com/blog,作为临时“修复”。 该块看起来像这样: server { server_name mysite.com; root /var/www/mysite; include conf.d/common.conf.inc; # Redirect blog location / { rewrite / /blog redirect; } } 然而,这个失败,出现以下错误: testingnginxconfiguration:nginx:[emerg] / etc / nginx / sites-enabled / mysite中的重复位置“/”:7 这个问题 我们怎样才能有一个服务器块的location / {}为try_files 和redirect从/到/blog所有请求?

Apacheconfiguration – 重写所有虚拟主机的规则

我有我的Apache上的2个虚拟主机的以下configuration: www.domain.com和res.domain.com 。 第一个是开放第二个是仅限注册用户。 <VirtualHost *:80> ServerName www.domain.com DocumentRoot /website/www <Directory "/website/www"> Options FollowSymLinks AllowOverride All RewriteEngine On RewriteCond %{REQUEST_URI} !api/dispatch\.php$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^api/.*$ api/dispatch.php [L,QSA] </Directory> </VirtualHost> <VirtualHost *:80> ServerName res.domain.com DocumentRoot /website/res <Directory "/website/res"> Options FollowSymLinks AllowOverride All AuthType Basic AuthUserFile /website/res/users.sec <Limit GET POST> Require valid-user </Limit> </Directory> </VirtualHost> 我想所有的电话http://res.domain.com/api/ […]

多重规则Apache重写

我试图用mod_rewritebuild立一个五层深层次结构。 这是我在这一点上所做的。 它适用于最后两个级别(第一个和第二个规则),但不是在那之后。 任何帮助将不胜感激。 RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /mr/index.php?product_group=$1&product_family=$2&product_category=$3&product_sub_category=$4&product=$5 [C] RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /mr/index.php?product_group=$1&product_family=$2&product_category=$3&product_sub_category=$4 [C] RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /mr/index.php?product_group=$1&product_family=$2&product_category=$3 [C] RewriteRule ^([^/]*)/([^/]*)$ /mr/index.php?product_group=$1&product_family=$2 [C] RewriteRule ^([^/]*)$ /mr/index.php?product_group=$1 [L] 我不是一个服务器技术。 我是一个开发人员,只是无法弄清楚这一点。 这些规则中的每一个都能正常工作。 我需要规则从一个层面到五个层面,以及其间的每一个步骤。 我需要深入了解search引擎优化的风格导航。

Apache指令sorting:全局,前VHost或目录块

我从零开始设置我的第一个虚拟服务器(提供程序名称省略,但它是一个“滴”)。 我一直在使用WHM一段时间,我觉得我很熟悉它。 具体来说,这是一台运行Apache 2.4的Debian 8机器(它使用apache.conf而不是httpd.conf ) 无论如何,我很难弄清楚在哪里把我认为是全球指令(它们应该适用于每个站点)在每种情况下都可用。 简单的例子是设置默认字符集或启用mod_deflate来激活gzip。 更具体地说,我已经写了重写规则来处理不需要的引用(spam referrer,但我不需要关于这个问题我非常熟悉的build议)。 这基本上是我所拥有的: <IfModule mod_rewrite.c> RewriteEngine on Options FollowSymlinks RewriteCond %{HTTP_REFERER} (badreferer1\..*) [NC,OR] RewriteCond %{HTTP_REFERER} (crappy-referer2\..*) [NC,OR] RewriteCond %{HTTP_REFERER} (webiste-i-hate3\..*) [NC] RewriteRule ^(.*)$ http://%1 [R=301,L] </IfModule> 我很确定我的RegEx是正确的(我想redirect所有的协议,所有的子域和所有包含这些string的TLD)。 我的理解是,如果将这些规则添加到每个vhost指令块中,这些规则就可以工作,但似乎非常多余。 我会很好地应用这些规则在全球范围内,但将其添加到我的apache.conf顶部是行不通的 我是否需要将它们包装在<Directory>块中? 我可以把它们放在<Directory />吗? 我的所有网站都在/var/www/html ,是否需要在<Directory /var/www/html>应用这些规则? 我错过了什么(不是在代码方面,因为这个片段是不完整的,但在订购指令和知道把它们放在哪里)? 我想保持我的.conf文件尽可能简洁,避免使用.htaccess (而不是AllowOverrides出于性能的原因),所以我想弄清楚如何让这个工作在apache.conf (把他们在一个通过include调用的文件是可以接受的,因为已经有几个正在使用)。

如何编写一个RewriteRule来匹配不存在的文件?

如何编写一个RewriteRule ,它首先检查请求的文件是否存在,如果不存在,则redirect到根页面: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule "^/(.*)" "/" [L] 例如http://example.com/not_existing_file应该redirect到http://example.com 。 但是这不起作用。 这里有什么问题?

.htaccess重写错误

我有我的网站http://example.com/category_name/product_name的结构。 我通过使用以下RewriteRule重写它到PHP: RewriteRule ^(.*)/(.*)/$ detail-produktu.php?kategorie=$1&nazev=$2 但是,当我尝试重写地址http://example.com/user/david时发生问题。 这个URL总是以/user开头,所以我想重写它: RewriteRule ^user/(.*)/$ index.php?user=$1 但是用/user的URL仍然是detail-produktu.php 。 我能做什么?