douzhang8144 2015-05-01 11:07
浏览 20

Mod Rewrite - 如何获取文件夹和参数?

I've searched the web and stack-overflow for this, and got a few answers. Oddly enough, they just don't work and I can't figure out why!

I have an index.php file that receives the URL folders and parameters. For example: example.com/folder1/folder2/?param=a&param2=b I am echoing them inside the index.php like this:

<?php
     echo "<pre>";
     echo "Folders: "; print_r($_GET['folders']);
     echo "<br>";
     echo "Parameters: "; print_r($_GET['parameters']);
     echo "</pre>";
?>

And this is the output that I get:

 Folders: folder1/folder2/
 Parameters: folder1/folder2/

This is the htaccess that I use:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?folders=$0&parameters=$1 [QSA,L]

How do I achieve an output like this:

 Folders: folder1/folder2/
 Parameters: a/b/

(or inside an array. Anything that would let me work with later)

  • 写回答

2条回答 默认 最新

  • doukenqiong0588 2015-05-01 11:58
    关注

    I got it! Damn. It was so obvious!

    .htaccess has nothing to do with it. The parameters will appear inside index.php using $_GET['some_parameter']

    You can see all parameters using:

    echo "<pre>";
    echo "All parameters: ";
    print_r($_GET);
    echo "</pre>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多