htaccess的动态PHP - 子文件夹的问题 [英] .htaccess with dynamic php - subfolder problems

查看:135
本文介绍了htaccess的动态PHP - 子文件夹的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必要的知识

我的.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

这篇关于htaccess的动态PHP - 子文件夹的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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