Php Reddit-Like子文件夹重定向

Php Reddit-Like子文件夹重定向,php,.htaccess,subdirectory,Php,.htaccess,Subdirectory,范例 实际上是给我们看的 http://www.reddit.com/r/example 一直显示在浏览器URL栏中。我知道这涉及到.htaccess,但每当我想到如何在谷歌上搜索解释时,它确实向我展示了与我的意思完全不同的解释,所以我很抱歉,因为我确信之前有人问过这个问题。你。htaccess文件应该是这样的: http://www.reddit.com/r/somepage.php?query=example 例如index.php,请记住将页面存储在名为pages # Do not r

范例

实际上是给我们看的

http://www.reddit.com/r/example

一直显示在浏览器URL栏中。我知道这涉及到.htaccess,但每当我想到如何在谷歌上搜索解释时,它确实向我展示了与我的意思完全不同的解释,所以我很抱歉,因为我确信之前有人问过这个问题。

。htaccess
文件应该是这样的:

http://www.reddit.com/r/somepage.php?query=example
例如
index.php
,请记住将页面存储在名为
pages

# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^(.+)$ index.php?p=$1 [QSA,L]

文件

我认为,对于您的具体示例,有一些关于如何完成类似任务的最有用的建议。它基本上归结为捕获
/r/([a-z]+)
并将其转换为
/r/somepage.php?query=$1
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php
        if(isset($_GET['r'])){
            if(file_exists('pages/' . $_GET['r'] . '.php')){
                include'pages/' . $_GET['r'] . '.php';
            }
            else{
                echo 'This page does not exist';
            }
        }
        else{
            include'pages/home.php';
        }
    ?>
</body>
</html>