htaccess 301重定向到.html [英] htaccess 301 redirect to .html

查看:184
本文介绍了htaccess 301重定向到.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我本来希望我的页面可以使用文件扩展名,也可以不使用文件扩展名。

I originally wanted my pages to work with and without the file extensions.

这是我正在工作的htaccess的样子:

This is what my working htaccess looked like:

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重定向。

I would like to reverse the above and force all pages to resolve to .html. I would like to include 301 redirects for Google.

推荐答案

RewriteEngine  on
RewriteRule ^(.*)$ $1.php

例如,这将正确重写 example.com/test 作为对 example.com/test.php

For example, this will correctly rewrite example.com/test as a request for example.com/test.php

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

you can remove both php html extensions by the following code

<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>

这篇关于htaccess 301重定向到.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆