Articles of mod rewrite

Apache RewriteRule 502在开发服务器上的错误,在现场工作

我在Apache 2.2.15上。 我的vhost.conf包含一个RewriteRule来处理文章的URL; # handling for neat article titles RewriteRule ^/news/[0-9]{4}/[A-za-z]{3}/([0-9a-zA-Z-]*)/([0-9]{4})([0-9]{6})/?$ "/news/article.cfm?clk=$2&article_id=$3&urltitle=$1" [P,L] 这是在我们的活服务器上正常工作,但是在我的本地开发服务器上,当我尝试加载文章时,浏览器中出现502错误: Proxy Error The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /news/2015/news-article/0123012345. Reason: DNS lookup failure for: localhost.example.com Apache/2.2.15 (CentOS) Server at localhost.example.com Port 80 这是我在错误日志中得到的; [Wed Oct 28 10:00:25 […]

在htaccess中像foreach的东西?

我在这种情况下: url: domain/var1/var2/var3/…/varn 我想在以下url中更改该url: url: domain?v1=var1&v2=var2&v3=var3/…/&vn=varn 我发现这样: RewriteRule domain/([^/]+)/([^/]+)$ domain/index.php?v1=$1&v2=$2 [QSA,NC] 但是,正如你所看到的,我必须手动指定所有的variables…有没有办法自动做到这一点? 类似于:有一个/([^/]+)加v{N}=${N} ? 谢谢

Htaccess使用单个RewriteRuleredirect到https和www

我有我的.htaccess文件中的以下内容: RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\. RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 它在浏览器中按预期工作,将所有stream量redirect到https://www.example.com/ 。 但我使用的POS系统自动将产品上传到网站,显然这个桌面应用程序不喜欢多个RewriteRule 。 它抱怨说,它的networking商店没有安装。 只要我删除了其中的一条规则,就很高兴。 所以我的问题是:有没有办法将它合并成一个RewriteRule ?

将用户redirect到任意应用程序协议(由Android应用程序使用)

我有一个Android应用程序,它使用内部协议来声明一个意图。 您可以通过打开包含以下链接的网页来启动它: myapplication://foo-bar 我想在我的网站上的一个url,将301redirect到自定义,内部,制定的协议。 这个想法是,我们的Android应用程序将在用户点击该链接时启动(应用程序已经安装)。 我可以简单地在HTML页面中添加一个anchro链接,但是我不能修改这个HTML。 我必须使用Apache。 我试过这个mod_rewrite规则: RewriteRule "^/app$" myapplication://foo-bar [R=permanent,L] 但是它总是在前面加上主机名,所以我在Location头得到这个: Location: https://example.com/myapplication://foo-bar 我如何指示mod_rewrite使用myapplication://foo-bar的URL( myapplication://foo-bar )?

Apache 2.2代理反向重写

当我尝试将apache 2.2configuration为代理服务器时,我遇到了一个问题。 我有一个应用程序运行在我的后端服务器http://internal.mydomain.com/App1/ ,现在这个URL将成为$URL ,因为我是一个新人在这里,我无法在我的第一篇文章发布超过2个url。 如果在我的代理服务器上,我使用下面的configuration一切工作正常 UseCanonicalName off UseCanonicalPhysicalPort off ProxyPreserveHost On ProxyPassReverseCookieDomain internal.mydomain.com external.mydomain.com ProxyPass /App1/ $URL connectiontimeout=10 timeout=60 ProxyPassReverse /App1/ $URL 要访问的URL是external.mydomain.com/App1/ 但是,我的老板想要有一个不同的URL,像external.mydomain.com/my/app1/ ,所以我尝试了以下configuration UseCanonicalName off UseCanonicalPhysicalPort off ProxyPreserveHost On ProxyPassReverseCookieDomain internal.mydomain.com external.mydomain.com ProxyPass /my/app1/ $URL connectiontimeout=10 timeout=60 ProxyPassReverse /my/app1/ $URL 这应该工作,但是当我加载网页,后端服务器正在回答这个 Cache-Control: private Content-Type: text/html; charset=utf-8 Location: /App1/StartPage.aspx Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 […]

.htacces重写规则不起作用

我有一个非常简单的重写规则,但它不工作。 我有以下几点: #old see edits for newer versions RewriteCond %{HTTP_REFERER} ^localhost:8080(/|$) RewriteRule ^/downloads/.* /somePackage/index.php?id=5 [NC,C] RewriteRule ^/downloads /somePackage/index.php?id=2 [NC,L] 它似乎没有通过RewriteCond ,为什么是这样呢? 当我尝试这个: RewriteRule downloads/? /somePackage/index.php?id=2 [NC,L] 它似乎工作localhost:8080/downloads 但是当我尝试: RewriteRule downloads/.*/? /somePackage/index.php?id=5 [NC,L] 它不起作用,为什么这不起作用? 我应该怎么做呢? 编辑: 我这是目前的代码,只适用于localhost:8080/downloads和localhost:8080/downloads/但不是当我添加一些东西后斜线 RewriteRule downloads/somedownload/? /somePackage/index.php?id=5 [NC,L] RewriteRule downloads/? /somePackage/index.php?id=2 [NC,L] 编辑2: 这里是使用的.htaccess代码。 # Only the URLs /downloads and /downloads/ (with and […]

根目录下的Apache + mod_auth_tkt + mod_rewrite + mod_proxy

我有一个运行在Apache服务器后面的Tomcat服务器上的Web应用程序,我使用mod_proxy将请求从httpd转发到tomcat服务器。 httpd服务器正在使用mod_auth_tkt进行身份validation,将有关用户的信息存储在环境variablesREMOTE_USER中。 我把这个variables从httpd传递给使用mod_rewrite的tomcat服务器,将其保存为头(X-Forwarded-User)。 ProxyPass设置为 httpd_server/app/ -> tomcat_server/app/ 这是vhost.conf: <Location /> RewriteEngine On RequestHeader unset X-Forwarded-User RewriteCond %{LA-U:REMOTE_USER} (.+) RewriteRule .* – [E=RU:%1,NS] RequestHeader add X-Forwarded-User %{RU}e </Location> <IfModule mod_proxy.c> ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /app/ http://127.0.0.1:8084/app/ ProxyPassReverse /app/ http://127.0.0.1:8084/app/ </IfModule> 这完美的作品。 但是,如果尝试将ProxyPass更改为 httpd_server/ -> tomcat_server/app/ 所以把vhost.conf改成: ProxyPass / http://127.0.0.1:8084/app/ […]

这个WordPress的.htaccess规则是什么?

在WordPress 4.7多站点子域安装的默认.htaccess规则中,我试图理解一个特定规则的目的。 首先我会自己提出这个规则 RewriteRule ^(wp-(content|admin|includes).*) $1 [L] 在我看来,这个规则似乎只是简单地将wp-content或者wp-admin或者wp-includes中的任何url重写到自己。 由于它是在文件系统检查之后发生的,我们知道它在文件系统上不存在,所以我不知道它要做什么。 现在这里是整个build议的.htaccess文件。 这条规则从结尾第三。 RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ – [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*\.php)$ $1 [L] RewriteRule . index.php [L] 任何人都可以摆脱的任何洞察力都是太棒了。 我收到一个错误 […]

RewriteRule指向域名parsing为127.0.0.1

我试图在Apache中设置代理,如下所示: <VirtualHost *:80> ServerName test.public.domain … RewriteRule "^/dir/(.*)" "http://x-service.local/$1" [P,L] … 在同一台服务器上还有另一个虚拟主机configuration: <VirtualHost *:80> ServerName x-service.local … 在Apache服务器上的/etc/hosts我有以下条目: x-service.local 127.0.0.1 当我从我的工作站curl test.public.domain/dir/xxx我得到5xx代码。 当我从服务器本身curl x-service.local/xxx ,我得到了200个代码。 当我改变 x-service.local 127.0.0.1 至 x-service.local 192.168.1.1 curl test.public.domain/dir/xxx工作正常。 192.168.1.1是服务器接口的IP地址。 apache听取0.0.0.0:80 没有防火墙 看起来像代理到域parsing为回送接口由于某种原因不起作用。 我不明白为什么我想知道如何使它工作,因为这样的设置将简化我的configuration多个服务器。

在VirtualHost的范围内的Apache request_uri

此代码在.htaccess或目录中完美工作 RewriteEngine on RewriteCond %{request_uri} !^/dir/$ [NC] RewriteRule ^(.*)$ /dir/ [END] 但是当放入VirtualHost时会导致无限的redirect。 我已经阅读了有关虚拟主机和目录中的request_uri之间差异的文档,但是我仍然无法生成将在虚拟主机上下文中工作的代码。 我应该改变什么?