removing ?page=add_theme from the url

Viewed 43

Lately I have been trying something and was trying to add a theme system like wordpress ( not creating a whole new wordpress ) just trying to implement their login.

I have this index.php file

<?php
    include('core/core.php');

    echo $_GET['id'];

    $currentTheme = getPageData() -> theme_selected;
    
    include("jtq-theme/" . $currentTheme . "/index.php");

?>

so this basically displays http://xxxxx/jtq-theme/default/index.php on the main page. So now when a person goes to the about us page.

so index.php is the main file that displays everything. and the about us page is being showing using the logic

http://xxxx/index.php?page=about_us

but I want the url to be

http://xxxx/about_us

and the file should be grabbed from http://xxxx/jtq-theme/default/about_us.php

How should I write the .htaccess in this case?

1 Answers

Add this rewrite rules to your htaccess file:

RewriteCond %{QUERY_STRING}    "page=" [NC] 
RewriteRule (.*)  /$1? [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

It will change your request from xxxx/index.php?page=about_us to xxxx/about_us

Update:

For getting data in about_us page you should add a condition in your index.php file:

<?php
    include('core/core.php');

    echo $_GET['id'];

    $currentTheme = getPageData() -> theme_selected;

    $page = $_GET['page'];    
    if ($page == "about_us") {
        include("jtq-theme/" . $currentTheme . "/about_us.php");
    } else {
        include("jtq-theme/" . $currentTheme . "/index.php");
    }
    

?>
Related