htaccess 301重定向到.html

编程入门 行业动态 更新时间:2024-10-14 00:27:22
本文介绍了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/test 作为对 example/test.php

For example, this will correctly rewrite example/test as a request for example/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

本文发布于:2023-10-31 13:43:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546257.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!