我想在我的网站的根目录索引文件是index.html但在一个子目录/foo我希望它是bar.html 即 /index.html /foo/bar.html 另外我想请求/foo或/foo/或/foo/:anything要parsing到bar.html /foo/:anything 为什么我的位置阻止/ foo工作? 如何为/ foo指定位置块? 这是服务器定义: server { listen 80; server_name domain.tld; port_in_redirect off; location / { # ssl is terminated at our load bal if ($http_x_forwarded_proto != 'https') { rewrite ^ https://$host$request_uri? permanent; } root /usr/share/nginx/mysite/public; index index.html; add_header Cache-Control "public max-age=600"; add_header "X-UA-Compatible" "IE=Edge,chrome=1"; charset UTF-8; } # […]
我正在尝试将cdn.minora.me/forum/中的每个文件重写到另一个目录中: server { listen 443 ssl; listen [::]:443 ssl; ssl on; ssl_certificate /etc/nginx/ssl/minora.me.crt; ssl_certificate_key /etc/nginx/ssl/minora.me.key; root /srv/minora.me/webservices/cdn.minora.me; index index.html index.htm index.php; server_name cdn.minora.me; location ~* \.(eot|ttf|woff|js|css|svg)$ { add_header Access-Control-Allow-Origin *; } location /forum/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) { alias /srv/minora.me/webservices/forum.minora.me/public/; } location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm-cdn.minora.me.sock; fastcgi_index index.php; […]
使用在Ubuntu 12.04上运行的Haproxy 1.5.12 我的网站得到很多像这样的请求: http://www.example.com/foo/bar/mypage.php?gallery=&position=3 正确的URL应该是: http://www.example.com/foo/bar/mypage.php?gallery=photogallery&position=3 我已经成功地将请求重写到正确的URL,但我也想发出301redirect到客户端。 以下这篇文章: 使用haproxyredirect重写的URL我试过: acl fix_gallery url_sub gallery=& reqrep (.*)gallery=&(.*) \1gallery=photogallery&\2 redirect prefix / code 301 if fix_gallery 试图有创意我试过了: acl fix_gallery url_reg (.*)gallery=&(.*) acl fix_gallery urlp_reg(gallery) -m str "" acl fix_gallery urlp_reg(gallery) -m len 0 还有很多。 但似乎没有任何工作,所以我显然失去了一些东西。 有什么build议么? 谢谢
您好新的网站启动。 前网站有这样的url: http://example.com/something.htm 新网站没有,看起来像这样: http://example.com/something 我怎么能告诉nginx做这个redirectpermanetly(301)。 我已经尝试rewrite ^(.*)$ $1.htm permanent; 没有成功。 location ~*\.(htm)${ rewrite ^(.*)$ $1.htm permanent; }
我正在做一些应该很简单的事情,但是第二天就会碰壁。 urlredirect要求是: 非www => www 非https => https /file.html => /utilities/template_handler.php?filename=file.html 问题:当我要求https://example.com/file.html我得到r = 301到 https://example.com/utilities/template_handler.php?filename=https://www.example.com/file.html 我的.htaccess : RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301] RewriteRule ^(.*)\.html$ /utilities/template_handler.php?filename=$1.html [NC] 我使用litespeed web服务器,但为了解决故障的目的也设置了Apache,结果也是一样。 打开debugging后,我看到: strip base: '/' from URI: '/file.html' Rule: Match 'file.html' with pattern '.*', […]
我正在通过mod_wsgi在同一个apache实例上运行几个django项目,每个站点都configuration了虚拟主机,请参阅这里的httpd.conf。 对于我想使用静态caching( staticgenerator )的站点之一,所以我build立了一个.htaccess文件的目录,其中包含: RequestHeader unset X-Forwarded-Host RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}/index.html !-f RewriteRule ^(.*) http://127.0.0.1:3456/$1 [P] 其中3456是服务器上的django端口。 使用这个重写规则,即使文件或目录存在,请求总是被转发到mod_wsgi处理程序,并且如果文件index.html存在,请求显示为request-path/index.html 。 我尝试了另一个设置: RequestHeader unset X-Forwarded-Host RewriteEngine on RewriteBase / RewriteCond $1 !-d RewriteCond $1index.html !-f RewriteRule ^(.*) http://127.0.0.1:3456/$1 [P] 但得到了几乎相同的结果。 所有请求都被传送到mod_wsgi处理程序,但请求path现在是原始的。 把它们加起来: 什么是在这里使用正确的RewriteCond? 你如何将请求传输到mod_wsgi处理程序? 这是正确的方式吗? 如果不是这样做,那么如何在目录中存在静态文件时,如何从apache / mode_wsgi提供静态文件? 谢谢你的帮助。
我们的域名/app/index.php正在iframe中加载domain.com/blog。 所以我的redirect规则应该是这样的; – domain.com/ => /app/index.php – domain.com/blog(.*) => /app/index.php?(.*) 第二条规则是因为如果有人想直接去博客,我们首先运行我们的应用程序,并将博客放在iframe中,并将传入的查询string附加到iframe src标记,以便它不打开它的主页,而是打开请求的URL。 问题是,因为我redirect我的第一条规则,iframe结束了无限循环。 它试图无休止地把自己放入另一个iframe中。 有没有办法分配一个Env var,这样如果redirect,它不会重复? 或者为了清楚地解决这个问题,我不希望博客在没有应用程序的情况下打开。 我的htaccess应该如何? 感谢:D ps:我们想在htaccess上做,因为php + jsredirect是低效率和丑陋的。
我正在研究安装在自己的子文件夹中的博客,所以文章的URL如下所示: 我需要它看起来像这样: http://www.sampleurl.com/article 我不能把它安装在根目录下,所以一个mod重写就能做到这一点,如果是这样,如何? 谢谢!
我试图让mod_rewrite规则工作在Debian Lenny上的Apache 2.2下。 为了让它工作,我把规则放在/etc/apache2/mods-enabled/rewrite.load中: RewriteEngine On RewriteRule http-poll/ http://jabberserver:5280/http-poll [P] RewriteLog "/tmp/rewrite.log" RewriteLogLevel 3 但是,当我重新启动Apache后使用浏览器去http:// localhost / http-poll时,我得到404错误。 Error.log有: [Wed Jun 30 15:22:53 2010] [error] [client 127.0.0.1] File does not exist: /var/www/http-poll “/tmp/rewrite.log”是空的。 我已经启用模块(包括mod_rewrite)(a2enmod重写代理proxy_http)
我需要强制所有的请求,而不pipe它们是什么index.html。 不幸的是,我所尝试的一切都没有正常工作。 以下似乎应该工作,但它不。 我的理解是,对于任何不以/index.html结尾的内容来实际请求index.html文件。 redirect302!^ / index.html http://www.example.com/index.html 任何帮助/澄清将不胜感激。