繁体   English   中英

如何导航到我网站的另一个页面而无需重新加载php中的标头

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

到目前为止,我一直在使用GET变量,当单击链接/按钮时,该变量将传递到URL,然后index.php页面将加载该页面。

例如-默认情况下,网站会加载index.php页面,其中包括header.phphome.phpfooter.php 单击关于我们按钮时,会将GET变量?page = aboutUs is passed to URL and then index.php includes aboutUs.php along with header.php and footer.php`。

但我不想让变量传递,而是我希望url像.../home/.../aboutUs/

还有其他方法吗?

最简单的方法是使用重写。

在这里您可以找到ApacheNginx的文档

使用.htaccess制定重写规则。

尝试这个:

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

我认为这应该工作。 只是重定向像

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

而且页面应该在about.php类的about.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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