duanjia1870 2015-12-02 12:57 采纳率: 0%
浏览 22

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 .

  • 写回答

2条回答 默认 最新

  • douying0108 2015-12-02 13:57
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染