我目前正在将所有内容redirect到app / index.html,因为我有一个客户端单页面应用程序。 但是,我想跳过实际的文件和目录redirect。 我已经得到这个了。 但是,当我在RewriteCond中添加跳过目录的文件时,它也会计算文档根目录。 这会导致访问文档根目录(如打到http://localhost:8080来列出我的目录内容。 我怎么会得到这个不适用于文档根目录或任何其他更好的方法? PS我也跳过/ api目录。 这是我到目前为止: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/api RewriteRule ^(.*)$ /app/index.html/$1 [NC] 所以基本上我猜我在问什么:如何跳过除了文档根目录之外的目录? 解 在Krist van Besien ( Krist van Besien给我的答案的帮助下,我能够find解决办法。 # not a directory RewriteCond %{REQUEST_FILENAME} !-d [OR] # or if it is the document root RewriteCond %{REQUEST_URI} ^/$ # not a […]
我想用apache2build立健壮的多用户开发环境。 所以我把以下文件放在etc/apache2/sites-available/mydomain.com <virtualhost *:80> ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /var/www/mydomain.com/prod </virtualhost> <virtualhost *:80> VirtualDocumentRoot /var/www/mydomain.com/%1 ServerName dev.mydomain.com ServerAlias *.dev.mydomain.com </virtualhost> 然后将以下.htaccess文件复制到每个/var/www/mydomain.com/*目录中: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [QSA,L,NS] Finaly它适用于像http://mydomain.com/这样的请求,但不适用于http://mydomain.com/foo 。 Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if […]
<IfModule mod_rewrite.c> RewriteEngine On RewriteLog "/private/var/log/apache2/rewrite.log" RewriteLogLevel 3 RewriteCond %{REQUEST_URI} !^/etc$ [OR] RewriteCond %{REQUEST_URI} !^/libs$ [OR] RewriteCond %{REQUEST_URI} !^/bin$ [OR] RewriteCond %{REQUEST_URI} !^/home$ [OR] RewriteCond %{REQUEST_URI} !^/var$ [OR] RewriteCond %{REQUEST_URI} !^/content$ [OR] RewriteCond %{REQUEST_URI} !^/siteadmin$ RewriteRule ^/([^/]*)/([^/]*)/(.*)$ /content/wu/$2_$1/$3 [PT,L] </IfModule>
我需要定义规则(使用mod_rewrite我认为)映射任何端口portnumber.domain.com 。 如何在Apache2中做到这一点? 现在我有一个像下面的每个端口号的configuration。 # 9003.domain.com <VirtualHost *:80> ServerName 9003.domain.com ProxyPreserveHost On ProxyPass / http://127.0.0.1:9003/ ProxyPassReverse / http://127.0.0.1:9003/ </VirtualHost> # 9004.domain.com <VirtualHost *:80> ServerName 9004.domain.com ProxyPreserveHost On ProxyPass / http://127.0.0.1:9004/ ProxyPassReverse / http://127.0.0.1:9004/ </VirtualHost> # and so on….
出于商业原因,我为Apache 2.2.22(mod_rewrite)创build了以下重写规则: RewriteRule /site/(\d+)/([^/]+)\.html /site/$2/$1 [R=301,L] 如果给出了这样的url: http: //www.mydomain.com/site/ 0999 / document.html 被翻译成: http : //www.mydomain.com/site/ document / 0999 .html 这是预期的情况。 但是,有名称只是数字的文件。 所以考虑下面的情况: http://www.mydomain.com/site/ 0055/0666 .html 获取翻译成: http://www.mydomain.com/site/ 0666/0055 .html 这也符合我的重写规则模式,所以我最终浏览器的“网页导致了太多的redirect”错误。 我研究了很长时间,没有find“好”的解决scheme。 我试过的东西: 使用[END]标志。 不幸的是我的Apache版本不可用,也不适用于redirect。 在RewriteCond子句上使用%{ENV:REDIRECT_STATUS}来结束重写过程(L)。 出于某种原因,%{ENV:REDIRECT_STATUS}在我尝试的所有时间都是空的。 如果我的规则匹配,添加一个带有Header子句的响应头,然后检查这个头( 详情请看这里 )。 似乎a)REDIRECT_addHeader为空b)标题不能明确地设置在301响应上。 还有另一种select。 我可以设置一个查询参数的redirectURL,这表明它来自redirect,但我不喜欢这个解决scheme,因为它似乎hacky。 有没有一种方法可以完成[END]标志的function,但是在旧的Apache版本中呢? 比如我的2.2.22。 谢谢!
我有一个Web服务器,它设置为不同的域dynamic服务不同的文档根 <VirtualHost *:80> <IfModule mod_rewrite.c> # Stage sites :: www.[document root].server.company.com => /home/www/[document root] RewriteCond %{HTTP_HOST} ^www\.[^.]+\.server\.company\.com$ RewriteRule ^(.+) %{HTTP_HOST}$1 [C] RewriteRule ^www\.([^.]+)\.server\.company\.com(.*) /home/www/$1/$2 [L] </IfModule> </VirtualHost> 这使得www.foo.server.company.com将服务于server.company.com:/home/www/foo/的文档根目录:/ server.company.com:/home/www/foo/ 对于这些网站之一,我需要添加一个ProxyPass ,但我只希望它被应用到该网站。 我试过类似的东西 <VirtualHost *:80> <Directory /home/www/foo> UseCanonicalName Off ProxyPreserveHost On ProxyRequests Off ProxyPass /services http://www-test.foo.com/services ProxyPassReverse /services http://www-test.foo.com/services </Directory> </VirtualHost> 但是,我得到这些错误 ProxyPreserveHost不允许在这里 ProxyPass | ProxyPassMatch在位置中定义时不能有path。 […]
在iOS应用程序中,我将Apple Game Center用户的小型化身上传到networking服务器,然后上传到/ios-avatars/ dir。 但有些玩家没有任何图片。 通过使用Apache mod_rewrite是否可以将“找不到”请求redirect到像/ios-avatars/GC123456789.png这样的文件到/images/default.png ?
嘿所以我试图使用Apache的mod_rewrite模块做一些基本的url在我的网站上的重新调整,所以他们变得更友善一点 基本上我有一个虚拟主机文件,看起来像这样 <VirtualHost *:80> ServerAdmin [email protected] ServerName mind-knowledge.com ServerAlias www.mind-knowledge.com DocumentRoot /var/www/tagmenu <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/tagmenu> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all <IfModule mod_rewrite.c> RewriteEngine on RewriteRule /video/([0-9]+) /PlayVideo/index.php?videoID=13424 </IfModule> </Directory> </VirtualHost> 现在从我的理解重写规则应该允许http://www.mind-knowledge.com/PlayVideo/13424/呈现为页面http://www.mind-knowledge.com/PlayVideo/index.php?videoID=13424是否正确? 目前我得到404,我已经运行sudo a2enmod rewrite和重新加载Apache。 任何人都可以帮我在我做错了什么或build议一些方法来解决问题,在此先感谢。 布兰登
我有以下虚拟主机文件: <IfModule !wsgi_module> LoadModule wsgi_module modules/mod_wsgi.so WSGISocketPrefix run/wsgi </IfModule> <VirtualHost *:80> RewriteEngine On RewriteLog "/var/log/httpd/rewrite_log" RewriteLogLevel 1 RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L] </VirtualHost> <VirtualHost *:443> ServerName https://tendril-api.dev.adnxs.net ServerAlias 06.tendril-api.dev.nym2.adnexus.net/api RewriteEngine on RewriteRule ^docs$ docs/ [R] … # SSL & WSGI Setup </VirtualHost> 出于某种原因,我的docs重写规则根本没有生效。 为什么是这样? 我的HTTP – > HTTPS重写规则在*:80 VirtualHost中正常工作。 我正在做一些非常相似的事情。 这是否与在不同的VirtualHosts中有两个不同的重写规则有关? 有任何想法吗?
在a2enmod rewrite ,我写了文件/etc/apache2/conf-available/myspecific_rewrite.conf : RewriteEngine on RewriteRule ^/test(/.*)?$ http://anothersite.tld/test$1 [R] RewriteRule ^/test2(/.*)?$ http://anothersite2.tld/test [R] 然后我在/etc/apache2/conf-enabled创build了a2enconf myspecific_rewrite和正确的符号链接。 问题是这个conf不起作用:重写是不活跃的。 我想要重写所有我的虚拟主机。 我写的这个文件定义了一个<VirtualHost>之外的RewriteRule …有没有办法让它工作?