0

I am working on redesigning a website that is currently a PHP website. The new site will be all HTML. I am trying to keep all of the slugs the same. Should I set up redirects?

Currently, the website pages have the .PHP extension in the browser.

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

The new page will be HTML and the URL will have no file extension.

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

Do I need to set up redirects as the file extension will be changing?

  • 1
    Does this answer your question? [How to link to pages without the .html extension?](https://stackoverflow.com/questions/16919526/how-to-link-to-pages-without-the-html-extension) – SMAKSS Oct 09 '20 at 22:41
  • I don't think so as they are asking how to remove the file extension from their permalinks, rather than the file extension actually changing from .PHP to .HTML. Unless the file extension does not matter if it is not shown? – Ryan Moreno Oct 09 '20 at 22:45
  • Does this answer your question? [How to change the PHP file extension using .htaccess file on GoDaddy Linux Hosting?](https://stackoverflow.com/questions/7897353/how-to-change-the-php-file-extension-using-htaccess-file-on-godaddy-linux-hosti) – Martin Oct 09 '20 at 22:55
  • If the resource has moved (under a different URL), a 301 from old to new is appropriate. – Progrock Oct 09 '20 at 22:59

2 Answers2

0

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.

In this .htaccess file you put:

# 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.

Reference:

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?

Martin
  • 22,212
  • 11
  • 70
  • 132
0

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. " https://www.dehartsystems.com/residential.html " only then your website will work., i.e you should rename residential.php to residential.html

  • you do not *need* to rename anything. – Martin Oct 10 '20 at 08:48
  • We don't need to rename php to HTML but the questions say without any extension, I hope it doesn't work without any extension right? there should be either PHP or HTML,extention. – Praneeth Avvari Oct 10 '20 at 17:49
  • 1
    You should look into `mod_rewrite` which makes URLs without extensions the standard these days – Martin Oct 10 '20 at 19:16