[英]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.