【发布时间】:2017-10-11 13:41:37
【问题描述】:
我最近将我的网站移至 wordpress。我需要将我的.html 重定向到.php。由于我的网站位于根文件夹中,我不希望 .htaccess 中的任何重定向影响我的子文件夹以及其中的其他站点。
是否有规则将它们重定向到我的特定网站?
【问题讨论】:
标签: php html .htaccess redirect http-status-code-301
我最近将我的网站移至 wordpress。我需要将我的.html 重定向到.php。由于我的网站位于根文件夹中,我不希望 .htaccess 中的任何重定向影响我的子文件夹以及其中的其他站点。
是否有规则将它们重定向到我的特定网站?
【问题讨论】:
标签: php html .htaccess redirect http-status-code-301
使用 .htaccess 应该是最好的方法。
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://mt-example.com/`
# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/`
# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html
这里还有一个关于如何创建 .htaccess 和编辑的视频
【讨论】:
在你的根 htaccess 的顶部,把这个:
RewriteEngine on
RewriteRule ^(.+)\.html$ /$1.php [L,R]
这会将所有 html 请求重定向到 php 例如: /file.html 到 /file.php R 是一个临时重定向标志,您可以将其更改为 R=301 当您确定规则正常工作时永久重定向。
【讨论】: