How can I change my URLs on my website?

Right now they are just the file name. For example www.mywebsite.com/events.html. I’d like to change all the links on my page so they do not have to end in .php or .html. Do you do this with javascript or php?

Hi @stevenhayes97!

You can do this using some .htaccess directives. Please append the following code to /public_html/.htaccess (in a new line):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

This will hide the extension of .html files.

I put that in my .htaccess, but it didn’t get rid of the.html extension. I did control + f5 too.

HTID:1821884: DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES BELOW

php_value display_errors 1
php_flag output_buffering on

DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES ABOVE HTID:1821884:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

My rule helps you to access the URL without .html

I though this is what you were asking for.

input id=“button” type=“button” value=“Events” onclick=“window.location.href=‘events’”

No it was I just forgot to take off the .html at the end. Thank you.

Can this work for .php too?

I have already added support for PHP as well :wink:

1 Like

Thank you! That makes my links a little prettier. I appreciate your help, and sorry for that confusion.

You’re welcome :blush:

Don’t worry. Any time :wink:

1 Like