【问题标题】:htaccess 301 redirect to .htmlhtaccess 301 重定向到 .html
【发布时间】:2016-08-23 04:59:27
【问题描述】:

我最初希望我的页面可以使用和不使用文件扩展名。

这是我工作的 htaccess 的样子:

RewriteEngine On

# .php to .html
RewriteCond %{THE_REQUEST} \ /(.+)\.php[?\s] [NC]
RewriteRule ^ /%1.html [L,R=301]

# don't need extension on the end
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^(.+)\.html/?$ $1.php [L,NC]

我想颠倒上述情况并强制所有页面解析为 .html。我想为 Google 添加 301 重定向。

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:
    RewriteEngine  on
    RewriteRule ^(.*)$ $1.php
    

    例如,这将正确地将example.com/test 重写为对example.com/test.php 的请求

    您可以通过以下代码删除两个 php html 扩展

    <IfModule mod_rewrite.c>
    Options +MultiViews
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php
    #RewriteRule ^([a-z]+)\/?$ $1.php [NC]
    
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html
    #RewriteRule ^([a-z]+)\/?$ $1.html [NC]
    
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2013-09-12
      • 1970-01-01
      • 2011-05-01
      • 2011-01-03
      • 2012-03-10
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多