【问题标题】:HTML to PHP redirect for website in my root folder?根文件夹中网站的 HTML 到 PHP 重定向?
【发布时间】:2017-10-11 13:41:37
【问题描述】:

我最近将我的网站移至 wordpress。我需要将我的.html 重定向到.php。由于我的网站位于根文件夹中,我不希望 .htaccess 中的任何重定向影响我的子文件夹以及其中的其他站点。

是否有规则将它们重定向到我的特定网站?

【问题讨论】:

    标签: php html .htaccess redirect http-status-code-301


    【解决方案1】:

    使用 .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 和编辑的视频

    Video creaton and edition of .htaccess in wordpress

    【讨论】:

      【解决方案2】:

      在你的根 htaccess 的顶部,把这个:

      RewriteEngine on
      
      RewriteRule ^(.+)\.html$ /$1.php [L,R]
      

      这会将所有 html 请求重定向到 php 例如: /file.html/file.php R 是一个临时重定向标志,您可以将其更改为 R=301 当您确定规则正常工作时永久重定向。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-23
        • 1970-01-01
        • 2013-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        相关资源
        最近更新 更多