.htaccess 从 .html 重定向到 .php 不起作用

问题描述 投票:0回答:1

我将根目录中的 10 个页面从

.HTML
更改为
.PHP
文件。 我正在尝试进行重定向,以便当有人转到
www.example.com/page_cats.html
时,它会自动重定向到
www.example.com/page_cats.php
。 我不想使用正则表达式或一般规则,因为大多数页面仍然采用“旧”
.HTML
格式,而需要重定向的页面只有 10 个。我想为 10 个重定向编写 10 行代码。

在 Stackoverflow 上寻找一些答案后,我编写了以下代码,但仍然无法正常工作(我在 MacBook 上使用 Ampps)。

RewriteEngine On
# Specific redirects 
Redirect /page_cats.html https://www.example.com/page_cats.php
Redirect /dogs_img.html https://www.example.com/dogs_img.php

为什么这不起作用?

php html .htaccess http-redirect
1个回答
0
投票

如果您想使用 Redirect 指令,您可以使用下面的代码。

# Specific redirects 
Redirect 301 /page_cats.html http://www.example.com/page_cats.php
Redirect 301 /dogs_img.html https://www.example.com/dogs_img.php

如果你想使用 RewriteRule 指令,那么你可以使用下面的代码:

RewriteEngine On

# Specific redirects
RewriteRule ^page_cats\.html$ https://www.example.com/page_cats.php [R=301,L]
RewriteRule ^dogs_img\.html$ https://www.example.com/dogs_img.php [R=301,L]

请告诉我这是否适合您

© www.soinside.com 2019 - 2024. All rights reserved.