所有子目录使用root index.php文件 [英] All subdirectories to use root index.php file

查看:231
本文介绍了所有子目录使用root index.php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现有的.htaccess文件看起来是这样的:

My existing .htaccess file looks like this:

Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^(.+/)?posts/(.*)/(.*).html$ index.php?content=blog&postid=$2&kwd=$3
RewriteRule ^(.+/)?aposts/(.*)/(.*).html$ index.php?content=autopost&postid=$2&kwd=$3
RewriteRule ^(.+/)?category/(.*)/(.*).html$ index.php?content=category&cat=$2&otext=$3
RewriteRule ^(.+/)?content/(.*).html$ index.php?content=$2
RewriteRule ^(.+/)?searching/(.*).html$ index.php?content=search&k=$2
RewriteRule ^(.+/)?related/(.*).html$ index.php?content=related&k=$2
RewriteRule ^(.+/)?blog/(.*)/(.*).html$ index.php?content=blog&postid=$2&kwd=$3
RewriteRule ^(.+/)?posts$ index.php?content=blog
RewriteRule ^(.+/)?sitemap\.xml$ sitemap.php [L]
RewriteRule ^(.+/)?robots\.txt$ robots.php [L]
ErrorDocument 404 /404.php

我想补充的能力,为所有子目录使用root index.php文件。例如,如果一个访问者进到根目录:

I would like to add the ability for all subdirectories to use the root index.php file. For example, if a visitor goes to the root directory:

example.com

他们得到服务的根本index.php文件。

They get served the root index.php file.

我希望它这样,如果有人去其他任何子目录,例如:

I want it so that if anybody goes to any other subdirectories eg:

example.com/sub1
example.com/sub1/sub2/sub3/etc..

他们从根目录送达的index.php文件,但在浏览器地址栏仍显示子目录,如:

They get served the index.php file from the root directory BUT the browser address bar still shows the subdirectories, eg:

example.com/sub1
example.com/sub1/sub2/sub3/etc..

正在展示了如何添加例外此规则将是巨大的。

Being shown how to add exceptions to this rule would be great too.

感谢您的帮助。

推荐答案

右键在的RewriteBase / 补充:

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond $1 !^index\.php
RewriteRule ^(.+)$ /index.php [L]

要添加例外,只需添加更多的的RewriteCond 行。例如,做起来很 /富/ 不被路由到index.php,添加:

To add exceptions, just add more RewriteCond lines. For example, to make it so /foo/ doesn't get routed to index.php, add:

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond $1 !^foo/
RewriteCond $1 !^index\.php
RewriteRule ^(.+)$ /index.php [L]

这篇关于所有子目录使用root index.php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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