Htaccess重写条件问题(Htaccess Rewrite Condition Issue)

编程入门 行业动态 更新时间:2024-10-15 20:20:36
Htaccess重写条件问题(Htaccess Rewrite Condition Issue)

我正在尝试关注Paul Irish的示例,了解如何在/publish建立我的网站的缩小版本。 我已成功集成自动构建过程但无法将.htaccess文件指向正确的文件夹。

我的目标:

在实时服务器上将所有正常站点流量重定向到/publish文件夹以使用“构建”站点。 但是当在开发服务器上使用/ normal根文件夹中的开发文件时。

我的问题:

我希望htaccess将请求从root重写到/publish目录。 由于在/和/publish目录中将使用相同的htaccess,我需要一个重写条件来阻止它将/publish目录中的请求重写到/publish/publish/my-page 。 我现在有这个:

RewriteCond %{SCRIPT_FILENAME} !^/publish/.+ RewriteRule ^(.*)$ publish/$1 [L]

上面的条件查找没有以/publish开头的script_filename请求。 如果是这样,它应该使用publish/ in重写请求。

但是,这不起作用。 有没有人有什么想法呢? 我可以使用不同的服务器变量来识别请求是否在/publish目录中。

I am trying to follow Paul Irish's example of how to have a built minified version of my site inside /publish. I have successfully integrated the automated build process but can't get the .htaccess file to point to the correct folder.

My Aim:

When on live server to redirect all normal site traffic to the /publish folder to use the 'built' site. But when on the development server to use the development files in the / normal root folder.

My Problem:

I want the htaccess to rewrite requests from the root to the /publish directory. As the same htaccess be will used inside the / and /publish directory I need a rewrite condition to stop it rewriting requests inside the /publish directory to /publish/publish/my-page. I have this at present:

RewriteCond %{SCRIPT_FILENAME} !^/publish/.+ RewriteRule ^(.*)$ publish/$1 [L]

The condition above looks for requests that do not have the script_filename starting with /publish. If so it should rewrite the request with publish/ in front.

However, this is not working. Does anyone have any ideas what is wrong with it? Could I use different server variables to identify if the request is in the /publish directory or not.

最满意答案

您应该使用%{REQUEST_URI}因为它是具有相对于站点根目录的路径的正确变量,而不是其他物理文件名。

RewriteCond %{REQUEST_URI} !^/publish/ RewriteRule ^(.*)$ publish/$1 [L]

You should use %{REQUEST_URI} instead as it is the correct variable that will have path relative to the site root and not physical file name like others.

RewriteCond %{REQUEST_URI} !^/publish/ RewriteRule ^(.*)$ publish/$1 [L]

更多推荐

本文发布于:2023-08-07 06:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   条件   Htaccess   Issue   Condition

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!