阿帕奇 - mod_rewrite的如何$目录的对$ PFER文件,而不是(如果两者都具有相同的名称)? [英] Apache - mod_rewrite how to prefer files instead of directories (if both have same name)?

查看:78
本文介绍了阿帕奇 - mod_rewrite的如何$目录的对$ PFER文件,而不是(如果两者都具有相同的名称)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个非常类似的问题:<一href="http://stackoverflow.com/questions/2659830/apache-mod-rewrite-$p$pfer-files-over-directories-with-$p$ptty-urls">Apache mod_rewrite的 - 在与目录preFER文件pretty的网址

I have very similar problem like this one: Apache mod_rewrite - prefer files over directories with pretty URLs

但它不是一样的,而在上面的链接中提到的解决方案并没有为我工作。

However it is not same, and solutions mentioned in above link doesn't work for me.

我的目录结构是这样的:

My directory structure looks like this:

/pages/articles/january.php
/pages/articles.php
/pages/home.php
/articles/
/index.php

现在,我包括的index.php网页(根据URL)。

Now, I am including in index.php pages (depending on url).

例如,当用户键入地址 www.domain.com (或 www.domain.com/home ),的index.php 将包括 /pages/home.php

For example, when user types address www.domain.com (or www.domain.com/home), index.php will include /pages/home.php

但是,如果我进入这个网址: www.domain.com/articles 它会让链接是这样的: www.domain.com/articles/?page [] =文章(即的index.php 将不包括 /pages/articles.php 文件)

But if I enter this URL: www.domain.com/articles it will make link something like this: www.domain.com/articles/?page[]=articles (in other words index.php won't include /pages/articles.php file)

在另一方面,这个完美的作品: www.domain.com/articles/january

On the other hand, this works perfectly: www.domain.com/articles/january

这是我的htaccess文件:

This is my htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9+]*)/([a-zA-Z0-9+]*)$ %{DOCUMENT_ROOT}/index.php?page[]=$1&page[]=$2 [QSA,L]
RewriteRule ^([a-zA-Z0-9+]*)$ %{DOCUMENT_ROOT}/index.php?page[]=$1 [QSA,L]

我用数组,因为我可以有子页面(和子页面做工精细!)。

I use array for page because I can have subpages (and subpages work fine!).

编辑:我已经找到<一href="http://stackoverflow.com/questions/7666487/how-to-$p$pvent-apache-mod-rewrite-from-treating-path-as-file-with-same-name">this但它并没有解决我的问题:(

I have found this however it doesn't solves my problem :(

谁能告诉我它为什么这个问题以及如何解决它?

Can someone tell me why it does this and how to fix it?

或者,我怎么能以文件为主,而不是目录?

Or, how can I give priority to files instead directories?

编辑2:我解决它通过删除/篇/目录下,但我仍然有兴趣如何使它工作,通过htaccess文件的规则

推荐答案

根据上面的评论,你原来的问题是围绕通过删除的文章目录的工作,但你还是希望能够处理目录在那种情况下

Per the comments above, your original issue was worked around by removing the articles directory, but you still wanted to be able to deal with directories in that sort of situation.

您很可能要分成两套规则。有使用 -d 标记在的RewriteCond 赶上目录,以便它可以作为区别对待他们更早规则必要的。另外,忽略第一个规则目录通过否定的标志。( - D!),然后赶上他们在以后的规则

You'd probably want to split into two sets of rules. Have an earlier rule that uses the -d flag in a RewriteCond to catch directories so that it could treat them differently as needed. Alternately, ignore directories in the first rule by negating the flag (!-d) then catch them in the later rule.

这篇关于阿帕奇 - mod_rewrite的如何$目录的对$ PFER文件,而不是(如果两者都具有相同的名称)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆