2017-07-25 14:35
浏览 80


I want to set up a custom template system for a website that I'm working on, so I want to redirect all requests to a single file. If the user visits an URL like I want to redirect his request to a file like index.php, so I could do something like the following:

$look_at = $_GET['first_level']; //for example: products
if($look_at == 'products') {
    $look_at = $_GET['second_level']; //here: software
    if($look_at == 'software') {
        //show software specific stuff
    } else if ($look_at == 'hardware') {
        //show hardware specicif stuff
    } else {
        //show error message
} else {
    //show error message

Then, I could use include to, well include, other html files into index.php depending on what is being requested.

In the end, a request like is supposed to be the same as

图片转代码服务由CSDN问答提供 功能建议

我想为我正在处理的网站设置自定义模板系统,所以我想重定向 对单个文件的所有请求。 如果用户访问了像 这样的网址,我想将他的请求重定向到 index.php 这样的文件,所以 我可以做类似以下的事情:

  $ look_at = $ _GET ['first_level'];  //例如:products 
if($ look_at =='products'){
 $ look_at = $ _GET ['second_level'];  //这里:软件
 if($ look_at =='software'){
}否则if($ look_at =='hardware'){
 // show hardware specicif stuff \  n} else {

然后,我可以 使用 include 来包含其他html文件到 index.php ,具体取决于请求的内容。

最后, 像 这样的请求应该与相同 products& second_level = software

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmou3615 2017-07-25 14:49
    RewriteEngine on
    RedirectMatch 403 /\..*$
    # If the directory or file exists, use them directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise, send a request to the index.php file
    RewriteRule . index.php

    Next in PHP example:

    if (($qpos=(strpos($URI,'/?')))!==false)
    elseif (($qpos=(strpos($URI,'?')))!==false)
    $URI = (preg_replace('/^\/|\/$/', '',$URI));
    解决 无用
    打赏 举报

相关推荐 更多相似问题