Articles of .htaccess

Apache Tomcat重写

我想要做的是设置一个重写规则,这样当一个URL被input时,它将显示为example.com/test 。 所以举个例子,我试图做到这一点,如果这是可能的。 我已经将site.example.com的CNAME设置为指向site.devexample.com (开发商的远程环境) 如果用户访问site.example.com则URL将重新写入这些行example.com/test 。 我到目前为止,但似乎没有工作,当我访问site.example.com它保持原样。 # rewrite rules for site.example.com RewriteCond %{http_host} ^site\.example\.com [NC,OR] RewriteCond %{http_host} ^www\.site\.example\.com [NC] RewriteRule $ http://example.com/test/ [R,L] 我需要做一个反向代理,然后从那里重新写? 编辑:我道歉,我应该更好一点解释。 site.example.com由test.com(A公司)拥有。 因此,我们将CNAME更改为指向site.devEnvironment.com(companyB.com) 而test.com/test是我们的服务器和目录,试图重写URL为test.com/test而不是site.example.com 我们的redirect在httpd.conf文件中设置,不知道这是否也有帮助

在php-fpm处理之前将所有* .php重写为单个index.php(apache)

传统应用程序通过Slim框架传递所有传统的PHP文件请求到index.php在.htaccess文件。 此外,Symfony应用程序在设置了别名的文件夹中设置。 用PHP-FPM进行VHostconfiguration <VirtualHost *:80> ServerName example.com DocumentRoot /path/to/app/slim Alias /system /path/to/app/symfony <IfModule mpm_itk_module> AssignUserId web_user web_user </IfModule> <LocationMatch "^(.*\.php)$"> ProxyPass fcgi://127.0.0.1:9001/path/to/app/slim </LocationMatch> </VirtualHost> testing文件: /path/to/slim/index.php <?php echo "slim"; /path/to/slim/.htaccess RewriteEngine On RewriteBase / RewriteRule ^hello$ /hello.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] /path/to/slim/hello.php: <?php echo "hello"; /path/to/symfony/app.php <?php echo "symfony"; […]

Apache2意外redirect:虚拟主机DirectoryIndex不自动提供index.php

我有两个安装在Ubuntu 16.04 VPS上的Apache虚拟主机。 site1.example.com是一个function正常的WordPress网站。 site2.example.com是一个新增的网站,其文档根目录中只有index.php 。 当我在浏览器中访问site2.example.com时,它意外地redirect到site1.example.com (WP网站)。 但是,如果我访问site2.example.com/index.php将按预期方式显示。 以下是/etc/apache2/sites-available中的.conf文件的内容: site1.conf: <VirtualHost *:80> ServerName site1.example.com DirectoryIndex index.html index.php DocumentRoot /var/www/html/site1.example.com/public_html </VirtualHost> site2.conf: <VirtualHost *:80> ServerName site2.example.com DirectoryIndex index.html index.php DocumentRoot /var/www/html/site2.example.com/public_html </VirtualHost> 我能做些什么来让http://site2.example.com/显示index.php而不需要在URL中明确要求? 如果有人有任何build议或需要看到我的configuration的另一部分,请让我知道。

使用Apache,将stream量重写到文件夹,然后redirect来自该文件夹的所有stream量

我有一个网站,目前正在从一个旧的CMS迁移到一个新的(Laravel)。 只有一些网站的语言已经被转移到Laravel。 所以基本上,我的虚拟主机的根文件夹是这样的: [D] staticContentDirectory1 [D] staticContentDirectory2 … [D] oldCmsDirectory1 [D] oldCmsDirectory2 … [D] oldCmsDirectoryN [D] public [F] index-of-the-old-cms-still-in-use.php 我有一个.htaccess文件,将旧CMS或静态内容目录中没有处理的所有内容redirect到Laravel,如下所示: RewriteRule ^((?!staticContentDirectory1|staticContentDirectory2|public)(.*))$ public/$1 [L] Laravel也有公开的.htaccess来处理它的东西。 到目前为止,一切工作都很完美,我们对结果非常满意(给定初始约束条件)。 我们发现了一个问题。 不知何故,谷歌设法发现/public存在并抓取它,导致与/public/里面,从那以后创build/public/public/ URLs(幸运的是,返回一个500错误,避免无限的URL)。 在修复CMS和robots.txt之前,我们试图通过将stream量从/public重写/redirect到/来解决这个问题。 很多事情都经过了尝试,发生了很多失败,几乎全部都是无限循环的redirect。 因为每个Apache模块似乎都是自己做的,混合RedirectMatch和RewriteRule失败了。 RewriteCond和RewriteRule是无限的redirect或完全忽略。 TL; DR:我现在正在寻求帮助:如何将RewriteRule /folder到/folder ,然后将所有stream量从该文件夹redirect到根目录。

.htaccess代码来阻止所有的.ua域名,但白名单一个特定的域名

我使用以下.htaccess代码阻止了一些垃圾邮件引用者: RewriteCond %{HTTP_REFERER} \.ru$ [NC,OR] RewriteCond %{HTTP_REFERER} \.ru/ [NC,OR] RewriteCond %{HTTP_REFERER} \.ua$ [NC,OR] RewriteCond %{HTTP_REFERER} \.ua/ [NC,OR] RewriteCond %{HTTP_REFERER} hol\.es [NC,OR] RewriteCond %{HTTP_REFERER} hys\.cz [NC,OR] A few more similar lines RewriteCond %{HTTP_REFERER} slinqs\.com [NC] RewriteRule ^(.*)$ – [F,L] 正如你所看到的,我使用代码阻止了所有的.ru和所有的.ua域名。 问题是现在我想允许一个特定的.ua域发送stream量到我的网站。 我如何将一个.ua域名列入白名单? 可能吗?

htaccess取代了完整的URL而不是REQUEST_URI

我正在做一些应该很简单的事情,但是第二天就会碰壁。 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,.htaccess和rewriterule

我正在通过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提供静态文件? 谢谢你的帮助。

.htaccess隐藏“上次修改”和“父目录”

我试图让我的.htaccess文件列出当前目录中的所有文件,隐藏“最后修改”列,并删除“花哨”风格的“父目录”的链接。 我当前的文件是: Options +Indexes 任何帮助将是伟大的! 谢谢

我如何让Apache为不同的域使用不同的本地PHP.ini?

是否有某种.htaccess指令。 我没有访问httpd.conf。 我有一个fastcgi / cgi模块中的php5。 多个域。 但由于某些原因,所有的域名都指向第一个域php.ini(我在脚本中安装了php) 不知道是否编译到构build,或者如果有一些设置我可以改变某个地方 非常感谢!

如何防止在htaccess无限redirect循环?

我们的域名/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是低效率和丑陋的。