Articles of 重写

用mod_rewrite重写基本URL

我的域example.com指向public_html目录。 在目录public_html / php是我的index.php文件。 现在我希望URL example.com指向public_html / php / index.php 。 我必须用mod_rewrite来做这件事,因为我没有访问httpd.conf来做别名或者DocumentBase。 在目录public_html是我的.htacces文件具有以下内容: RewriteEngine on RewriteCond %{HTTP_HOST} exaple.com$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /php/index.php [L,QSA] 这样做的一半,因为当我在我的浏览器中input像example.com/s的东西,它指向public_html / php / index.php,因为我希望它做。 但是,当我刚刚进入example.com它指向public_html 。 我能做些什么来解决这个问题?

将不存在的子域redirect到基本域url

我使用的是我的域名为“example.com”的Droplr,前缀为“u”。 (u.example.com)。 前置不是一个子域,并通过Aloggingredirect到Droplr服务器的IP地址。 编辑— 换句话说,我没有创buildu.example.com作为example.com的子域名,而是创build了一个Alogging,使其像子域一样。 不过,我将urux.com中使用的域名更改为example.com,我试图用.htaccess设置一个redirect来将任何请求转发到u.example.com/abcd到example.com/abcd 。 我目前有以下,但似乎没有任何影响的领域。 请你能告诉我哪里出错了吗? RewriteEngine on RewriteCond %{HTTP_HOST} ^u.example.com$ [OR] RewriteCond %{HTTP_HOST} ^www.u.example.com$ RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

将VirtualHostconfiguration为将HTTP:// subdomain …重写为HTTPS:// internaldirectory

如何configurationApache重写一个子域的http请求到正确目录的https请求? 例如,我有以下VirtualHostconfiguration: 不过,这会将http://redmine…us转换为https://redmine…us/redmine 。 另外,改变 RewriteRule ^(.*)$ https://%{HTTP_HOST}/redmine [R] RewriteRule ^(.*)$ https://%{HTTP_HOST} [R] 似乎只是将HTTP请求redirect到HTTP://…us ,这是当前默认的/var/www/index.html页面。 有什么build议么?

iis 7 url重写为search结果

我重写了特定目录的工作,但无法弄清楚如何让search结果重写工作。 如果直接进入/blog/?s=coffee ,则会转到正确的search结果页面。 但是由于其他url重写,search结果页面正在尝试去/?s=coffee/ 。 dynamic的内容部分扔给我。 我已经尝试了很多东西,但是玩笑 <rule name="Redirect long query string" stopProcessing="true"> <match url="^?s=(.*)$" /> <action type="Rewrite" url="blog/?s=$1" appendQueryString="false" /> </rule> 我不知道我在做什么。 这是一个奇迹,我得到了其他重写工作。

nginx url重写为php-urls

我不得不在nginx中redirect一些旧的url。 旧的url是旧式的PHPurl,包括加载内容的参数。 他们看起来像这样: http://www.foo.com/index.php?site=foo http://www.foo.com/index.php?site=bar 我想redirect他们到其他url,如: http://www.foo.com/news http://www.foo.com/gallery 任何意见,我怎么能做到这一点? 我的尝试失败了。 提前致谢!

重写新的URL并阻止nginx中的旧URL

我有一个本地文件夹/bar ,我想通过http://www.example.com/foo 。 所以我有这样的configuration rewrite ^/foo/(.*)$ /bar/$1 last; 同时,我想阻止公众访问真正的url /bar , 然后我像添加configuration location ~* ^/bar{ return 404; } 但是当我把这个URL添加到configuration中,上面的第一个configuration不起作用,现在都返回404 任何我应该修复,以使重写工作? 谢谢。

捕获URI的一部分,并用它在Nginx中进行条件重写

我正在写一个Nginxconfiguration的位置块,它是这样的模式的URI: www.mysite.com/a/b/blah/c或www.mysite.com/a/b/blah/c/n 。 如果a和b是固定的,那么blah可以改变, c可以是三个固定string(optionA,optionB,optionC)中的一个, n是从0,1,2等等开始的数字。 另外,只有当c等于optionB时n才有效,所以在其他情况下,Nginx应该在c之后立即抛出404 。 我打算写一个位置块如下: location ^~ /a/b/ { … } 我想在这个位置实现的逻辑:首先从一个给定的URI获取c ,并根据它的值,做三个可能的重写之一。 即 if (c = optionA) { rewrite … … break; } if (c = optionB) { rewrite … … break; } if (c = optionC) { rewrite … … break; } 我的问题是: 我已经读过, if语句应该在Nginx中的位置块通常避免,但它似乎与rewrite使用是一个例外。 我在这里rewrite的方式会导致任何问题吗? 如何捕获c并在这里实现条件重写逻辑?

IIS重写规则redirect并删除查询string

我试图从旧的网站到新的IIS 7.5重写。 我们有一个URL的列表,有和没有查询string。 我可以得到的URL没有查询stringredirect,但不是。 <rewrite> <rewriteMaps configSource="rewritemaps.config" /> <rules> <rule name="Redirect Rule" stopProcessing="true"> <match url=".*" ignoreCase="false" /> <conditions> <add input="{StaticRedirects:{URL}}" pattern="(.+)" /> </conditions> <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" /> </rule> </rules> </rewrite> 这是示例rewritemap: add key="/boat-insurance/canoe.aspx" value="/boat/canoe-insurance" (这个工作) add key="/boat-insurance/canoe/details.aspx?#details" value="/boat/canoe-insurance" (这不是)

为什么这个IIS重写不适用于Firefox和Chrome?

在我的Windows 2008R2服务器的IIS7.5中,我有一个url重写。 重写似乎可以在Internet Explorer中工作,但是Firefox和Chrome仍然给我一个404。如果不使用存储在caching中的内容,Firefox甚至会跳过redirect。 任何线索如何使这个权利? <rewrite> <rules> <rule name="Redirect site" patternSyntax="Wildcard" stopProcessing="true"> <match url="{HTTP_HOST}/site*" /> <conditions> </conditions> <action type="Redirect" url="http://site.domain.org" redirectType="Permanent"/> </rule> </rules> </rewrite>

nginx重写将域redirect到domain2

我想将www.mydomain.comredirect到www.mydomain2.com/try.html 。 这些域位于两个不同的服务器上。 这是我试过的,但不起作用: if ($http_referer ~* (www.mydomain.com) ) { return 301 http://www.mydomain2.com/try.html; } 要么 if ($http_referer ~* (www.mydomain.com) ) { rewrite ^ http://mydomain2.com/try.html permanent; } 这两种方式是行不通的,当我去mydomain.com我留在mydomain.com但是…没有CSS …而我没有redirect到mydomain2.com/try.html 任何帮助赞赏。