如果文件存在的mod

编程入门 行业动态 更新时间:2024-10-08 13:35:15
本文介绍了如果文件存在的mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经有一个正常工作,现在两个重写规则,但一些code已被添加到正常工作。

I already have two rewrite rules that work correctly for now but some more code has to be added to work perfectly.

我主持在mydomain和所有subdom.mydomain都rewrited到mydomain/subs/subdom网站。我CMS要处理的请求,如果不存在可触及的文件,重写是像这样做:

I have a website hosted at mydomain and all subdom.mydomain are rewrited to mydomain/subs/subdom . My CMS has to handle the request if the file being reached does not exist, the rewrite is done like so:

RewriteCond $1 !^subs/ RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ subs/%1/index.php?page=$1 [L]

我的CMS处理解析像往常一样下一部分。问题是如果文件确实存在,我需要不经过我的CMS链接到它,我成功地做到这一点是这样的:

My CMS handles the next part of the parsing as usual. The problem is if a file really exists, I need to link to it without passing through my CMS, I managed to do it like this:

RewriteCond $1 !^subs/ RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\$ RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ subs/%1/$1 [L]

到目前为止,似乎工作就像一个魅力。现在我被挑剔,我需要有存储在潜艇/默认/默认的文件。如果该文件存在于子域文件夹,我们应该抓住这一个,但如果没有,我们需要从默认的子域文件。如果该文件不存在任何地方,我们应该使用404页,从目前的子域,除非是没有的。

So far it seems to work like a charm. Now I am being picky and I need to have default files that are stored in subs/default/. If the file exists in the subdomain folder, we should grab this one but if not, we need to get the file from the default subdomain. And if the file does not exist anywhere, we should be using the 404 page from the current subdomain unless there is none.

我希望它描述不够好。感谢您的时间!

I hope it describes well enough. Thank you for your time!

推荐答案

现在的问题是,你需要提供绝对的文件系统路径来获得 -f 和 -d 工作。如果你在文档根目录,您可以使用此规则:

The problem is that you need to provide the absolute file system path to get -f and -d working. If you’re in the document root, you can use this rule:

RewriteCond $1 !^subs/ RewriteCond %{DOCUMENT_ROOT}/subs/default/$1 -f [OR] RewriteCond %{DOCUMENT_ROOT}/subs/default/$1 -d RewriteRule ^(.*)$ subs/default/$1 [L]

但是,如果你在别的地方,这将是很难得到正确的路径preFIX。

But if you’re somewhere else, it’s going to be hard to get the right path prefix.

更多推荐

如果文件存在的mod

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

发布评论

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

>www.elefans.com

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