Home htaccess RewriteRule passes index.php instead of string
Reply: 0

htaccess RewriteRule passes index.php instead of string

user1008
1#
user1008 Published in April 22, 2018, 12:59 am

So I'm trying to learn about .htaccess RewriteRules and am facing the following issue:

"/home" should open "index.php?page=home"

and I have a php $_GET['page'] inside "index.php", but it passes "index.php" instead of "home" every time.

Here are the files

.htaccess

RewriteEngine On
RewriteRule ^/?(.+)/?$ index.php?page=$1 [L]

index.php PHP part

<?php

        if(isset($_GET['page'])) {
            $path = $_GET['page'] . ".php";
            if (file_exists($path)) {
                include($path);
            }
            else {
                echo "File not found: " . $path;
            }
        }
        else {
            include("home.php");
        }

?>

The output is always:

File not found: index.php.php

I face this issue on both: web-server and apache.

Any suggestions? I'll update my question with more info if necessary.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308328 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO