# .htaccess help

**URL:** <https://forum.infinityfree.com/t/htaccess-help/43370>\
**Category:** Hosting Support\
**Created:** [March 26, 2021, 3:48pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370 "2021-03-26T15:48:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [March 26, 2021, 3:48pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/1 "2021-03-26T15:48:51Z")

</div>

Hi everyone!  
I’m trying to convince web browsers to remove the .html and .php extension, but they don’t seem to be listening.

Current Code:

 ![Inked6fa8582f3d0858884e4bf1a2fe751d0b9017e9d1_LI](https://forum-cdn.infinityfree.net/original/3X/9/b/9b1e2637ec920585a219c390ecac61f82ba808f6.jpeg)

Right now, the site works fine, weather the URL has the extension or not. ([removed.com&nbsp;-&nbsp;Informationen zum Thema removed.](http://REMOVED.com/Contact) & [removed.com&nbsp;-&nbsp;Informationen zum Thema removed.](http://REMOVED.com/Contact.html) both work) However, if you were to go to [removed.com&nbsp;-&nbsp;Informationen zum Thema removed.](http://REMOVED.com/Contact.html) it will not redirect you to [removed.com&nbsp;-&nbsp;Informationen zum Thema removed.](http://REMOVED.com/Contact). Does someone know if a line is preventing this from happening, or if I need to add something? Google searching has not turned up anything useful for me.

Thanks!!!

---

<div class="post-metadata">

**Author:** ![KangJL](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/kangjl/32/12130_2.png) [@KangJL](https://forum.infinityfree.com/u/KangJL)\
**Post date:** [March 26, 2021, 4:15pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/2 "2021-03-26T16:15:31Z")

</div>

Use `Options +MultiViews` to disable file extension

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [March 26, 2021, 4:16pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/3 "2021-03-26T16:16:28Z")

</div>

> [@Greenreader9](#):
>
> However, if you were to go to [REMOVED.com/Contact.html](http://REMOVED.com/Contact.html) it will not redirect you to [REMOVED.com/Contact](http://REMOVED.com/Contact).

There is no line to do that in your screenshot. The first “remove php file extension” line only does the thing you described first:

> [@Greenreader9](#):
>
> Right now, the site works fine, weather the URL has the extension or not. ([REMOVED.com/Contact](http://REMOVED.com/Contact) & [REMOVED.com/Contact.html](http://REMOVED.com/Contact.html) both work)

If you want to also redirect `Contact.html` to `Contact` (if the file exists, of course), you’ll need additional .htaccess rules to do that.

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [March 26, 2021, 5:04pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/4 "2021-03-26T17:04:11Z")

</div>

HI, can you explain to be how that would be done? I am new to htaccess, and it kind of looks like giberish here 🙂

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [March 26, 2021, 5:05pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/5 "2021-03-26T17:05:23Z")

</div>

> [@Admin](#):
>
> There is no line to do that in your screenshot.

That’s weird, because it works!

> [@Admin](#):
>
> you’ll need additional .htaccess rules to do that.

Do you have any idea what these could be?  
Thanks!

---

<div class="post-metadata">

**Author:** ![anon68194040](https://forum.infinityfree.com/letter_avatar/anon68194040/32/6_449c533f586939b6e5f246632a46421f.png) [@anon68194040](https://forum.infinityfree.com/u/anon68194040)\
**Post date:** [March 26, 2021, 5:18pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/6 "2021-03-26T17:18:13Z")

</div>

I can help you with that.

There’s a DreamHost article containing information about changing and removing file extensions (like the community guide i made where you can create extensions based off old ones)

From the [DreamHost Article:](https://help.dreamhost.com/hc/en-us/articles/215747728-How-can-I-control-file-extensions-with-an-htaccess-file-)  
This example completely removes the file extension from your URL. So, example.php would appear as example. The following example is for .php files, but for any other type, just replace .php with your desired type and add those lines and extensions in the same way:

```plaintext
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\ HTTP/
RewriteRule ^(.*)index$ http://example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.php\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/$1 [L,R=301]
RewriteRule ^([a-z]+)$ /$1.php [L]

```

You can also force it without the extension too by clicking the DreamHost Article button so this reply doesn’t go long.

---

<div class="post-metadata">

**Author:** ![anon68194040](https://forum.infinityfree.com/letter_avatar/anon68194040/32/6_449c533f586939b6e5f246632a46421f.png) [@anon68194040](https://forum.infinityfree.com/u/anon68194040)\
**Post date:** [March 26, 2021, 5:19pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/7 "2021-03-26T17:19:12Z")

</div>

This could help you but I haven’t tested it out yet. (DreamHost is a true source)

---

<div class="post-metadata">

**Author:** ![alexvf](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/alexvf/32/14357_2.png) [@alexvf](https://forum.infinityfree.com/u/alexvf)\
**Post date:** [March 26, 2021, 5:23pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/8 "2021-03-26T17:23:15Z")

</div>

I know that you can use this to remove the .php extension because it works for me:

```auto
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

```

I know that you can use this to remove the .html extension because it works for me on another website:

```auto
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

```

I don’t know how you can use both. If I had to do it, I would test it like this, **but I never tried it** and don’t have a clue if it works:

```auto
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

```

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [March 26, 2021, 5:29pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/9 "2021-03-26T17:29:57Z")

</div>

Thanks for the examples! I’ll check them out when I am free later and let you know how they work!

Edit: I can’t spell

---

<div class="post-metadata">

**Author:** ![YT\_Xaos](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/yt_xaos/32/45201_2.png) [@YT\_Xaos](https://forum.infinityfree.com/u/YT_Xaos)\
**Post date:** [March 26, 2021, 6:25pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/10 "2021-03-26T18:25:19Z")

</div>

The example @alexvf provided works.

---

<div class="post-metadata">

**Author:** ![TigerMANEK426](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/tigermanek426/32/12600_2.png) [@TigerMANEK426](https://forum.infinityfree.com/u/TigerMANEK426)\
**Post date:** [March 26, 2021, 8:37pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/11 "2021-03-26T20:37:35Z")

</div>

This exact code also works perfectly to remove .html and .php file extentions:

```auto
Options +MultiViews +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

```

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [March 26, 2021, 9:01pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/12 "2021-03-26T21:01:24Z")

</div>

Thanks so much @TigerMANEK426 @alexvf and @anon68194040! I wish I could mark all of your solutions as correct. Thanks for the code and explanations, it is much appreciated!

---

<div class="post-metadata">

**Author:** ![anon68194040](https://forum.infinityfree.com/letter_avatar/anon68194040/32/6_449c533f586939b6e5f246632a46421f.png) [@anon68194040](https://forum.infinityfree.com/u/anon68194040)\
**Post date:** [March 29, 2021, 3:19pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/13 "2021-03-29T15:19:11Z")

</div>

Glad to help!

---

<div class="post-metadata">

**Author:** ![system](https://infinityfree-forum-uploads.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/0/b024fd3fa88bae093c9576e55c2c94e33f890206.svg) [@system](https://forum.infinityfree.com/u/system)\
**Post date:** [April 13, 2021, 3:19pm UTC](https://forum.infinityfree.com/t/htaccess-help/43370/14 "2021-04-13T15:19:13Z")

</div>

Closed on April 13, 2021, 3:19pm UTC

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
