htaccess的动态PHP - 子文件夹的问题文件夹、动态、问题、htaccess

由网友(一秒メ速杀)分享简介:必要的知识 我的.htaccess文件重定向是这样的:domain.com/about到domain.com/index.php?page=about~~V My .htaccess file redirects like this:domain.com/about to domain.com/inde...

必要的知识

我的.htaccess文件重定向是这样的: domain.com/about到domain.com/index.php?page=about~~V

My .htaccess file redirects like this: domain.com/about to domain.com/index.php?page=about

RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]

用在PHP中的页面变量包括:

The "page" variable is used in a php include:

<?php include_once($_SERVER['DOCUMENT_ROOT']."/contents/".$page.".html"); ?>

内容文件夹中仅包含所包含的内容.html文件

The "contents" folder simply contains .html files that are included as the content

好这里有一个问题:

我有一个子文件夹中的内容文件夹,我需要获得额外的.html文件 现在,我想重定向这样的: domain.com/subfolder/about到domain.com/index.php?page=subfolder/about~~V

I have a "subfolder" in the "contents" folder with additional .html files that I need to access Now I'm trying to redirect like this: domain.com/subfolder/about to domain.com/index.php?page=subfolder/about

本作品:

RewriteRule ^([^/.]+/[^/.]+)/?$ index.php?page=$1

但现在我不能访问子文件夹:domain.com/subfolder/因为有一个页面变量

But now I can't access the subfolder from: domain.com/subfolder/ because there is a 'page' variable

<?php $page = $_GET['page']; if(!$page) { $page = 'index'; } ?>

任何想法,想法,或帮助将是很大的AP preciated。

Any thoughts, ideas, or help would be greatly appreciated.

在此先感谢

推荐答案

有了这个,你不应该定义任何目录名称 - 它排除他们都出去

With this, you shouldn't have to define any directory names - it rules them all out.

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

您可能需要测试,虽然结尾的斜线,它可能工作在/子文件夹/而不是/子目录

You may need to test the trailing slash though, it may work on /subfolder/ but not /subfolder

阅读全文

相关推荐

最新文章