简体   繁体   中英

how to navigate to another page of my website without reloading header in php

Till now I have been using GET variable which is passed to the URL when a link/button is clicked, then index.php page loads that page.

eg- by default website loads index.php page and it includes header.php , home.php , footer.php ; when about us button is clicked, GET variable ?page=aboutUs is passed to URL and then index.php includes aboutUs.php along with header.php and footer.php`.

But I don't want get variable to be passed, instead I want url to be like .../home/ and .../aboutUs/

Is there an alternative way?

The easiest approach is to use rewrite.

Here you could find documentation for Apache and Nginx

Use .htaccess to craft a rewrite rule.

Try this:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)/$ /$1.php
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    DirectoryIndex index.php
    ErrorDocument 404 /404-error.php

Ithink this should work. just redirect like

<a href="about">about</a>

and the page should be in php like about.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM