简体   繁体   English

我正在重新设计HTML 中的一个PHP 网站。是否因为文件扩展名需要设置重定向?

[英]I am redesigning a PHP website in HTML. Do I need to set up redirects because of the file extension?

I am working on redesigning a website that is currently a PHP website.我正在重新设计一个目前为 PHP 网站的网站。 The new site will be all HTML. I am trying to keep all of the slugs the same.新站点将全部为 HTML。我试图让所有的 slug 保持不变。 Should I set up redirects?我应该设置重定向吗?

Currently, the website pages have the.PHP extension in the browser.目前,网站页面在浏览器中的扩展名为.PHP。

Example: https://www.dehartsystems.com/residential.php示例: https://www.dehartsystems.com/residential.php

The new page will be HTML and the URL will have no file extension.新页面将为 HTML,而 URL 将没有文件扩展名。

Example: https://www.dehartsystems.com/residential示例: https://www.dehartsystems.com/residential

Do I need to set up redirects as the file extension will be changing?我是否需要设置重定向,因为文件扩展名会发生变化?

To answer your question, yes you do need to set up redirects.要回答您的问题,是的,您确实需要设置重定向。 Typically this is done in the .htaccess file in the root of your html folder on your server.通常,这是在服务器上.htaccess文件夹根目录下的 .htaccess 文件中完成的。

In this .htaccess file you put:在这个.htaccess文件中,你输入:

# Check rewriting is possible.
<IfModule mod_rewrite.c>
    # Turn on Rewrite engine
    RewriteEngine on
    # check if file does not exist.
    RewriteCond %{REQUEST_FILENAME} !-f
    # check if folder does not exist.
    RewriteCond %{REQUEST_FILENAME} !-d
    # rewrite the given URL.
    RewriteRule ^(.*).php$ $1.html [R=301,L]
</IfModule>

This will redirect any call to any.php file that does not exist to the HTML file with the same file name, in the same folder location.这会将对不存在的任何 .php 文件的任何调用重定向到同一文件夹位置中具有相同文件名的 HTML 文件。

Reference:参考:

https:/.htaccessbook.com/add-remove-change-file-extensions.htaccess/ https:/.htaccessbook.com/add-remove-change-file-extensions.htaccess/

See also How to change the PHP file extension using .htaccess file on GoDaddy Linux Hosting?另请参阅如何使用 GoDaddy Linux 主机上的 .htaccess 文件更改 PHP 文件扩展名?

Yes, you will need to rename every file to.HTML if you don't do so the browser won't recognize the file as code.是的,您需要将每个文件重命名为 .HTML,否则浏览器将无法将该文件识别为代码。 " https://www.dehartsystems.com/residential.html " only then your website will work., ie you should rename residential.php to residential.html https://www.dehartsystems.com/residential.html ” 只有这样你的网站才能正常工作,即你应该将 residential.php 重命名为 residential.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [HTML / PHP]:是否需要更改.html文件的扩展名 - [HTML/PHP]: Do I need to change the extension of .html file 我正在使用php和mysql.my开发网站,每个页面文件扩展名都以.php扩展名结尾如何避免这种情况? - I am developing website using php and mysql.my each page file extension end with .php extension how do i avoid that? 由于新的 php 版本,我是否需要更新 php 文件? - Do I need to update php file because of new php version? 我可以设置一个PHP文件作为文件扩展名的处理程序吗? - Can I set up a PHP file to act as a handler for a file extension? 301重定向PHP:我是否需要明确告诉它它是301? - 301 Redirects in PHP: Do I need to explicitly tell it that it's a 301? 由于Wordpress,我需要在javascript文件中使用PHP,我该怎么做,或者有什么更好的选择 - I need to use PHP in a javascript file because of Wordpress, how can I do that or whats a better alternative 我需要在带有html的php文件中使用!DOCTYPE声明吗? - Do I need a !DOCTYPE declaration in a php file with html? 我需要在包含的php文件中回显html吗 - Do I need to echo html inside included php file 我正在使用 mariadb 和 php7 创建一个网站,需要指导 - I am creating a Website using mariadb and php7 and need direction 错误310:重定向过多。 我正在编码的网站的php编码页面 - ERROR 310: too many redirects. Occurring with php coded pages for website I am coding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM