mod_rewrite嵌套目录到动态页面


mod_rewrite nested directory to dynamic page

我花了很多时间让这个工作起来
我有一个目录结构:

/province/city/business_name.php 

我想重写它,这样URL就可以保留下来,但它会为动态内容加载这个页面:

/listing.php?p=province&c=city&b=business

我到底是怎么在mod_rewrite中做到这一点的?似乎有很多解决方案,但没有一个对我有效

提前感谢您的帮助!

PHP

尝试此解决方案

首先,检查是否所有变量都不为空,然后,尝试检查路径是否正确以及文件是否存在。如果是正确的,您可以包括文件。

<?php    
        $province = $_GET['p'];
        $city = $_GET['c'];
        $business = $_GET['b'];
        if($province && $city && $business){
            if(file_exists('/'.$province.'/'.$city.'/'.$business.'.php')){
                include_once('/'.$province.'/'.$city.'/'.$business.'.php')
            }
        }
?>

啊!终于拿到了!

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+).php /listing.php?p=$1&c=$2&b=$3 [NC]

工作非常完美。