gpt4 book ai didi

.htaccess - htaccess 重定向并从 php 重写为 html

转载 作者:行者123 更新时间:2023-12-04 05:05:35 25 4
gpt4 key购买 nike

我被 .htaccess 修改困住了,需要一点帮助。
首先,这是我的 htaccess 里面的内容。

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

例如,我创建了名为 test.php 的文件并上传到我的服务器。

我希望我的服务器表现得像这样。
http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html

但是使用我现在拥有的 .htaccess,
我仍然拥有 .php 和 .html,它们可能被搜索引擎爬虫(如 Google 机器人)视为文件重复(不是吗?)。

任何帮助表示赞赏。

最佳答案

试试这个 .htaccess 代码

# Enable Rewrite Engine
RewriteEngine on

#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]


RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]


Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]

关于.htaccess - htaccess 重定向并从 php 重写为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15545170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com