-1

Example

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

is actually showing us

http://www.reddit.com/r/somepage.php?query=example

All the while, still showing http://www.reddit.com/r/example in the browser URL Bar. I know this involves .htaccess, but every time I think of how to search for an explanation on google, it really is showing me explanations to completely different things than what I am meaning, so I apologize as I'm sure this has been asked previously.

EasterEggs
  • 23
  • 3
  • 2
    I think for your specific example, [this question](https://stackoverflow.com/questions/25080835/pretty-urls-with-htaccess) has the most helpful suggestions on how to accomplish something like this. It basically boils down to capturing `/r/([a-z]+)` and turning it into `/r/somepage.php?query=$1`. – rickdenhaan Feb 19 '21 at 20:26

1 Answers1

0

You .htaccess file should like this:

# 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]

An example index.php, keep in mind to store your pages in a map named pages

<!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>
Tom
  • 606
  • 7
  • 28