URL重写仅在从主页单击链接时才有效

I have noticed my url rewrite code works fine only if i click a page the from homepage . If i click another page it just doesn't rewrite the url.

Example . i click contact page from homepage . it rewrites fine to site.com/page/contact . But if i click the about us page from the contact page , instead of displaying the about us page as site.com/page/about-us , it displays site.com/page/page.php?page=about-us .

here is my .htaccess code

AddDefaultCharset UTF-8
Header unset ETag
FileETag None

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+post\.php\?post=([^\s&]+) [NC]
RewriteRule ^ post/%1? [R=301,L]

RewriteRule ^post/([^/]+)/?$ post.php?post=$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+page\.php\?page=([^\s&]+) [NC]
RewriteRule ^ page/%1? [R=301,L]

RewriteRule ^page/([^/]+)/?$ page.php?page=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

I have little knowledge of url rewriting, it took me weeks to even get this to work. Please what did i write wrong ? Thanks

Link clicked from homepage site.com/page/page.php?page=about-us , rewrites to site.com/page/about-us.

Link clicked from any other page that has had its url rewritten , e.g. from about us page clicked earlier , Lets say i clicked the contact page from it site.com/page/page.php?page=contact , it should rewrite to site.com/page/contact , but it does not rewrite .

If I understand correctly, then you ought to be able to produce the redirects you need with something much simpler.

Something like:

RewriteEngine On

RewriteCond %{QUERY_STRING} page=(.+)
RewriteRule .* http://%{HTTP_HOST}/page/%1/? [NC,L]

in the .htaccess file in the root folder of your website.

Well i finally found a solution !

The solution is to just write the link as site.com/page/contact-us or site.com/page/about-us .

I thought i always had to write it as page.php?page="about-us" then after clicking , the rewrite happens .

I replaced page.php?page="about-us" with http ://site.com/page/about-us right in my script. And the page gets retrieved from the database. The URL stays clean even if i hop between pages. I don't know its possible to do that but for some reason it worked . Anyone who understands why this works should please explain . Thanks