我有以下 Nginx 配置:
server {
listen 80;
location /test {
rewrite /test(.*) /$1 break;
proxy_pass "http://www.example.com/";
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于主页,当输入“ http://localhost/test ”时,我得到了http://www.example.com/的内容,而 URL 仍然是“ http://localhost/test ”。
很酷,但是当我点击网站中的链接时,说/more_examples我希望将链接重写为: http://localhost/test/more_examples。在实践中,我得到以下信息:http://localhost/more_examples,这显然不起作用。这甚至可能吗?
任何帮助将不胜感激。
我安装了一个基于使用的子域的 Web 应用程序 (ClockingIT)。由于我们想使用 SSL 并且没有通配符证书,这对我们来说不是很方便:-) 所以我考虑使用 Apache 的 mod_proxy 和 mod_rewrite 功能。
更准确地说,我希望 URL Xttps://example.com/cit/(外部)显示 Xttp://test.example.com:3000/(内部)的内容。
这是我的设置:
<VirtualHost *:443>
ServerName example.com
(SSL setup, etc)
SSLProxyEngine On
UseCanonicalName Off
ProxyRequests Off
ProxyPreserveHost Off # or On, makes no difference
RewriteEngine On
RewriteRule ^/cit$ Xttp://test.example.com:3000/ [P,NC]
RewriteRule ^/cit/(.*)$ Xttp://test.example.com:3000/$1 [P,NC]
ProxyPassReverse /cit/ Xttp://test.example.com:3000/
Run Code Online (Sandbox Code Playgroud)
test.example.com 未在 DNS 服务器上定义,但在 /etc/hosts 中设置以映射到 127.0.0.1。如果我在服务器上执行“w3m Xttp://test.example.com:3000/”,我会得到正确的网页。但是,如果我在桌面浏览器上访问https://example.com/cit/,则无法获得正确的网页。Web 应用程序收到请求,但它似乎认为请求是针对 example.com 域的,并提供默认页面而不是预期的子域“测试”内容。似乎代理没有通过 test.example.com 域,尽管根据文档它应该。我还尝试了 ProxyPass 指令,而不是 RewriteRule,但结果相同。
有什么我想念的吗?
(如果相关,ClockingIT 是通过 Mongrel 提供的 Ruby on Rails 应用程序)
PS:s/Xttp/http/g …
如您所知,亚马逊 EC2 实例获得的地址如下:
ec2-72-44-40-153.z-2.compute-1.amazonaws.com
如果我有域 example.com,有什么方法可以让 bob.example.com 或最好是 example.com/bob 重定向到
ec2-72-44-40-153.z-2.compute-1.amazonaws.com
??
谢谢!!
我的 .htaccess 文件中有许多 RewriteRules。但是,只有在删除另一条特定规则时才会执行一条特定规则,而不管我如何对这两条规则进行排序。
这是似乎具有“较低”优先级的规则:
RewriteRule ^([0-9]+)$ /beta/forward.php?id=$1 [L]
Run Code Online (Sandbox Code Playgroud)
这是始终优先的规则:
RewriteCond %{HTTP_HOST} ^domain1\.net$ [NC]
RewriteRule ^(.*)$ http://domain2.net/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
domain1 和 domain2 实际上都指向同一个网站。因此,每当两个规则都在 .htaccess 文件中并且我访问
http://domain1.net/123
Run Code Online (Sandbox Code Playgroud)
第二条规则首先执行,我得到两次重定向,首先重定向到http://domain2.net/123,然后(当主机名不再适合第二条规则时)重定向到http://domain2.net/beta/ forward.php?id=123。我已经尝试修复第二条规则,因此它永远不会对只包含数字的 url 执行,但我一定是做错了什么,因为它仍然会被执行:
RewriteCond %{HTTP_HOST} ^ domain1\.net$ [NC]
RewriteRule ^(.*[^0-9]+.*)$ http://domain2.net/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
只有从 .htaccess 文件中删除这两行,我才能得到第一个规则来立即处理请求。
任何帮助将不胜感激。
我有一个子域,我想在其中保留我正在处理的项目,以便向客户展示这些项目。
这是来自 /etc/nginx/sites-available/projects 的配置文件:
server {
listen 80;
server_name projects.example.com;
access_log /var/log/nginx/projects.example.com.access.log;
error_log /var/log/nginx/projects.example.com.error.log;
location / {
root /var/www/projects;
index index.html index.htm index.php;
}
location /example2.com {
root /var/www/projects;
auth_basic "Stealth mode";
auth_basic_user_file /var/www/projects/example2.com/htpasswd;
}
location /example3.com/ {
index index.php;
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/example3\.com/(.*)$ /example3\.com/index.php?id=$1 last;
break;
}
}
location ~ \.php {
root /var/www/mprojects;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在子文件夹中放置不同的 php 引擎(wordpress、getsimple 等)。这些引擎具有不同的查询参数(id、q、url 等),因此为了使 preety …
在 Windows Server 2008 上安装了 Team Foundation Server 2010 后,我需要一个简单的 URL 供我们的开发人员访问他们的存储库。
TFS 存储库的默认 URL 是http://localhost:8080/tfs
现在我希望子域域 tfs.server.domain.com 指向http://localhost:8080/tfs。当您访问 tfs.server.domain.com/repos_name 时,它应该重定向到http://localhost:8080/tfs/repos_name。
我怎样才能在 IIS7 中做到这一点?
我已经尝试使用以下规则,但它不起作用。我得到一个 404。
<rewrite>
<globalRules>
<rule name="TFS" stopProcessing="true">
<match url="^(?:tfs/)?(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^tfs.server.domain.com$" />
</conditions>
<action type="Rewrite" url="http://localhost:8080/tfs/{R:1}" />
</rule>
</globalRules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
编辑
我实际上是通过在端口 80 上使用主机名 tfs.server.domain.com 为站点添加绑定来实现的。
但是使用 tfs.server.domain.com,我无法使用 Windows 身份验证进行身份验证。是否需要为 Windows 身份验证配置某些内容?
你可以在这里看到一个痕迹:http : //pastebin.com/k0QrnL0m
我正在尝试在 lighttpd 中设置一个反向代理,以便 /mobile/video 下的所有请求(并且只有那些请求)被重定向到辅助 Web 服务器的 / 目录。这在 apache 中很容易,但我一生都无法弄清楚如何在 lighttpd 中做到这一点。
$HTTP["url"] =~ "^/wsmobile/video/" {
url.rewrite-once = ( "^/wsmobile/video/(.+)" => "/$1" )
proxy.server = ( "" => ( ( "host" => "210.200.144.26", "port" => 9091 ) ) )
}
Run Code Online (Sandbox Code Playgroud)
我试过使用 http["url"] 指令,但是 lighttpd 只是忽略这些请求并继续将完整的 url 传递给辅助服务器,这当然会导致 404 阻塞和抛出。但是,如果我进行全局重写,那么所有内容都会转发到辅助服务器,这也不是我想要的。
我该如何完成这项任务?
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
...导致从“www 到非 www”的完美的非硬编码 301 重定向,完全相反的情况会是什么样子?
编辑:
根据 Prix 的帖子,我已将.htaccess文件更改为以下内容:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
如前所述,http://www./不幸的是,这重定向到。谁能帮忙?
我试图将访问我网站管理部分的任何人重定向到它的 HTTPS 版本。目前的重写规则如下:
server {
listen 80;
server_name domain.com;
location / {
index index.php index.html;
root /home/domain.com/public;
}
#Redirect Admin requests to secure server
location /www/admin/ {
rewrite ^/(.*) https://domain.com$1 permanent;
}
}
Run Code Online (Sandbox Code Playgroud)
此规则的问题在于它仅转发http://domain.com/www/admin到 HTTPS -http://domain.com/www/admin/index.php例如,不会重定向。知道如何纠正这个问题以便以下任何内容/www/admin也被重定向吗?
我是 Nginx 重写的新手,正在寻求帮助以获取有效且最小的重写代码。我们希望在活动材料上使用诸如“somecity.domain.com”之类的 URL,并将结果转到“www”站点中特定于城市的内容。
所以,这里是用例,如果客户输入:
www.domain.com (stays) www.domain.com
domain.com (goes to) www.domain.com
www.domain.com/someuri (stays the same)
somecity.domain.com (no uri, goes to) www.domain.com/somecity/prelaunch
somecity.domain.com/landing (goes to) www.domain.com/somecity/prelaunch
somecity.domain.com/anyotheruri (goes to) www.domain.com/anyotheruri
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我想出的,它部分有效。我不明白的是如何检查主机后面是否没有路径/uri,我猜可能有更好的方法来做到这一点。
if ($host ~* ^(.*?)\.domain\.com)
{ set $city $1;}
if ($city ~* www)
{ break; }
if ($city !~* www)
{
rewrite ^/landing http://www.domain.com/$city/prelaunch/$args permanent;
rewrite (.*) http://www.domain.com$uri$args permanent;
}
Run Code Online (Sandbox Code Playgroud) rewrite ×10
nginx ×4
apache-2.2 ×3
.htaccess ×2
redirect ×2
301-redirect ×1
cname-record ×1
directory ×1
iis ×1
iis-7 ×1
ip ×1
lighttpd ×1
mod-proxy ×1
mod-rewrite ×1
php ×1
proxy ×1
ssl ×1
url ×1