Articles of mod重写

未遵循.htaccess中mod_rewrite规则的顺序

我们正试图对某些url实施HTTPS,对其他网站实施HTTP。 我们也在重写url,所以所有的请求都通过我们的index.php。 这是我们的.htaccess文件。 # enable mod_rewrite RewriteEngine on # define the base url for accessing this folder RewriteBase / # Enforce http and https for certain pages RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # rewrite all requests for file […]

Apache报告本地IP而不是主机名

我有一个设置如下: 内部IP为10.10.0.4的Linux Server(OpenVZ) – Container(10.10.0.5) – Container(10.10.0.6) 由于IP空间有限,我只有一个公共IP映射到主服务器 192.168.1.2 => 10.10.0.4在networking侧。 现在在主要的主机上.4我有apache运行接受端口80上的连接等。与mod_proxy有这样的虚拟主机: <VirtualHost 10.10.0.4:80 192.168.1.2> ServerAdmin [email protected] ServerName host.example.com ServerAlias ct1.host.example.com ProxyPass / http://10.10.0.5/ ProxyPassReverse / http://10.10.0.5/ </VirtualHost> 并且有通配符DNS设置,以便* .host.example.com映射到192.168.1.2。 在容器上像这样设置了一个标准的虚拟主机: <VirtualHost 10.10.0.5:80 *:80> ServerName ct1.host.example.com ServerAlias ct1.host.example.com ServerAdmin [email protected] DocumentRoot /var/www <Directory /var/www/> Options FollowSymLinks AllowOverride All </Directory> Options Indexes FollowSymLinks ErrorLog /var/logs/error_log CustomLog […]

为LAMP应用程序设置负载平衡群集时应该知道些什么?

我应该说,“我如何build立一个负载均衡的Cluser”。 我不是一个系统pipe理员的任何价值.. apt-getted和百胜安装我的方式来云中的一些堆栈,但没有什么幻想。 现在我遇到了一个Drupal站点的问题,它已经超出了硬件的能力。 防火墙后面有两台服务器,在超高峰时间应用服务器达到90%以上,在同一时间,db / solr服务器很less超过10%(通常是3-4)。 这些是被pipe理的物理硬件。 DB非常重读。 从财务angular度来说,无论如何,即使没有configuration更改,也可以将其转移到云端。 所以我所想象的是负载平衡器运行mod_proxy之间的平衡请求2(我想有奇迹般地增长)的应用程序服务器与nfs同步与一个数据库服务器交谈。 目前应用服务器是DELL PowerEdge 2950 MKIII,内存为32GB,2.5ghz×4。Db与内存的一半相同。 两个都有15000 rpm的raid 1个设置。 所以真的,这似乎是可行的。 前期的负载平衡器似乎不需要任何东西,也许是1GB的图像? 如果用户在会话期间切换服务器,我发现某处可能存在cookie问题,有人可以对此进行说明吗? 任何一般的build议,学习更多的地方等等。记住,我真的只是想敲掉这个,而不是成为一个专家。 谢谢

如何使用mod_rewrite保证网站的一个页面安全

我想redirect访问从http到https的url只有我的网站几页。 我知道如何使用Apache虚拟主机中的重写整个网站: RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} 但有没有办法做到这一点的网站页面? 例如“www.example.com/protected-page”

如何将子域redirect到以子域为参数的域

我想redirect我的通配符子域到我的主域使用.htaccess的URL中的子域作为GET参数。 我想要发生的事情的例子: billy.example.com redirect到 www.example.com/profile?user_name=billy 以下是我基于本网站上的其他答案放在一起的现行规则: RewriteCond %{HTTP_HOST} ^(.*).example.com RewriteRule ^(.*)$ http://www.example.com/shop?user_name=%1 [R,L] 但是,当redirect发生时,我得到以下URL“redirect循环”错误: www.example.com/profile?user_name=www 我已经看到这个网站回答了几个不同的方式,但不幸的是他们都没有为我工作。 (我正在使用PHP,并且我在主机面板中设置了*作为子域。)

URL重写无限redirect问题

在我的.htaccess文件中,我有以下行: RewriteRule ^f/(.*)$ /blah.php?g=$1 我正在尝试使url如 example.com/f/three 被解释为 example.com/blah.php?g=three. 但是,像前者一样访问一个url会导致“最大内部redirect”错误。 我究竟做错了什么?

mod_rewrite:url重写加子域(通配符)同时重写

我有我的.htaccess文件URL重写两个规则: 对于子域重写:xxx.domain.com被内部redirect到file.php?item = xxx RewriteCond%{HTTP_HOST}!^ www.domain.com $ [NC] RewriteCond%{HTTP_HOST} ^(www。)?([^。] +)。domain.com $ [NC] RewriteRule ^ $ /file.php?item=%2 [QSA,nc] 2.一般重写: RewriteRule ^([A-Za-z0-9 _)(:! – ',] +)/?$ file.php?item = $ 1 [L] 我需要做的是编写第三条规则,将这两条规则结合起来而不与它们发生冲突。 也就是说,在这条线的下面(或上面)我需要有这样的东西 RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com/([A-Za-z0-9_)(:!-',]+)$ [NC] RewriteRule ^$ /anotherfile.php?item1=%2&item2=$1 [QSA,nc] 这样http://xxx.domain.com/yyy将被redirect到anotherfile.php?item1 = xxx&item2 = yyy 任何想法,将工作,或者是什么正确的方式呢?

防止在.htaccess中的RewriteRule循环

我正在尝试引入漂亮的url: RewriteRule ^(.*).html$ index.php?arianne_url=content/$1 [L] 而我想在外部重写访问旧式的url: RewriteCond %{QUERY_STRING} arianne_url=content/([^&]*) RewriteRule ^.* /%1.html? [R=301] 问题是这个循环无止境。 我试图定义env并检查它,但是这仍然导致无限循环 RewriteRule ^(.*).html$ index.php?arianne_url=content/$1 [L,env=arianne:rewrite] RewriteCond %{env:arianne} ^$ RewriteCond %{QUERY_STRING} arianne_url=content/([^&]*) RewriteRule .* /%1.html? [R=301] 我必须在.htaccess中执行此操作,因为我无权访问服务器configuration文件。 编辑: 日志文件: http : //pastebin.ca/1927769 # enable nice urls RewriteRule ^(.*).html$ index.php?arianne_url=content/$1 [L,env=arianne:rewrite] # Redirect old style request to new nice url RewriteCond %{env:arianne} ^$ […]

Apache / Unicorn:如何让Apache提供静态文件

我正在按照这个教程安装Apache +独angular兽,但似乎Apache不提供任何静态文件。 这里是我想出的configuration(看看Redirect all non-static requests to unicorn特别是): <VirtualHost *:80> ServerName www.unstilted.com:80 ServerAlias *.unstilted.com DocumentRoot /var/www/unstilted/current/public ErrorDocument 503 /system/maintenance.html RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{REQUEST_FILENAME} !/system/maintenance.html RewriteRule ^.*$ /system/maintenance.html [L] # Rewrite to check for Rails non-html cached pages (ie xml, json, atom, etc) RewriteCond %{THE_REQUEST} ^(GET|HEAD) RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_URI} -f RewriteRule ^(.*)$ /cache/%{HTTP_HOST}$1 [QSA,L] […]

带有包含空格的URL的Apache RewriteMap不起作用

我实际上在我的虚拟主机中使用RewriteMap指令来redirect800个URL的列表。 它工作安静: RewriteEngine On RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db RewriteCond ${redirects:$1} !="" RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last] 我使用包含映射的redirect.txt文件。 然后它被转换成一个数据库文件: httxt2dbm -f db -i /data/apps/project/current/configuration/etc/httpd/conf/redirects.txt -o /data/apps/project/current/configuration/etc/httpd/conf/redirects.db 例如对于这种types的URL,这是可以的: /associations/old_index.php / 但是当URL包含空格时,它不起作用:(我想这与其他特殊字符是一样的) /Universités%20direct / 如何处理这种情况?