【问题标题】:HTML file redirect [duplicate]HTML文件重定向[重复]
【发布时间】:2017-01-18 21:24:57
【问题描述】:

我不确定您是否会在 .htacess 文件中执行此操作,但是,

我有一个页面www.website.com/page2.html

如何使 URL 看起来像 www.website.com/page2

【问题讨论】:

    标签: html .htaccess redirect


    【解决方案1】:

    这应该适合你:

    example.com/page会显示example.com/page.html的内容

    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteEngine On
        RewriteBase /
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME}.html -f
        RewriteRule ^(.+)$ $1.html [L,QSA]
    </IfModule>
    

    301example.com/page.htmlexample.com/page

    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteEngine On
        RewriteBase /
    
        RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
        RewriteRule ^(.*)\.html$ /$1 [R=301,L]
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      在 apache 下使用 .htaccess,您可以像这样进行重定向:

      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)\.html$ /$1 [L,R=301] 
      

      至于从url中删除.html,只需链接到没有.html的页面

      <a href="http://www.website.com/page2">page</a>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-17
        • 1970-01-01
        • 1970-01-01
        • 2014-12-07
        • 2018-12-12
        • 2014-11-23
        相关资源
        最近更新 更多