1

I have been struggling with this all morning and I have not had much luck.

I am trying to get the following stackoverflow post to work: How to remove .html from URL

Here is my file directory with the htaccess file: enter image description here

Here is my code that works fine using .html enter image description here

So I went into sublime text and posted the same code into a .htaccess file as shown here (also in my directory first pic): enter image description here

I then changed my links and removed .html enter image description here

But I get an error enter image description here

If anyone could please tell me what I'm doing wrong I would be grateful! Been bashing my head on this all morning

Cœur
  • 37,241
  • 25
  • 195
  • 267
MMM
  • 315
  • 1
  • 6
  • 19
  • Consider if you simply want a text-based website, check out Sculpin or Jekyll, which output to flat files. You can also host your site on Github. There are other server technologies out there too, like nginx and lighthttpd (couple others I can't recall). I would recommend looking into the hobby versions of Heroku, Digital Ocean or Azure if you have a minimum comprehension of using git; they really nearly abstract the server out of the equation. Also look into docker-compose, and stay away from WAMP/XAMPP/MAMP. Please for the love of donuts don't serve a site to the world off your computer. – Jared Farrish Jun 25 '17 at 23:23
  • Hi Jared Farrish, this is all hosted on my personal github page. I uploaded pics from my local server only for the stack overflow post. On my github though the links go to index.html, resume.html, etc.. which is the reason I tried to find a solution – MMM Jun 25 '17 at 23:30
  • Local development, that's how it works; look into docker-compose, very easy to get something going (instead of *AMP stuff, which is long in the tooth technique). Don't run it for the world there, though; then deploy to a cloud-based provider on the cheap using git. Heroku's [Getting Started with PHP](https://devcenter.heroku.com/) is a pretty good intro. Just saying, give it a shot. – Jared Farrish Jun 25 '17 at 23:59
  • Rewriting urls is a feature of the server system you're using, whether it's Apache or nginx or Tomcat. That's really just detail. – Jared Farrish Jun 26 '17 at 00:02
  • https://store.docker.com/images/php – Jared Farrish Jun 26 '17 at 02:10

2 Answers2

2

.htaccess is a file used to control access for Apache web servers. It won't affect anything unless you're running and accessing an Apache server. From your screenshots I can see that you're directly opening a file from your hard drive.

Your browser is saying File not found because you're trying to access a non-existent file. The address bar in your browser should say this:

file:///Users/mikegeng/Documents/GitHub/MichaelGeng.github.io/index.html
Clonkex
  • 3,373
  • 7
  • 38
  • 55
  • Thank you Clonkex. I feel pretty dumb now. It says File not Found because I renamed it to " – MMM Jun 25 '17 at 23:09
  • @MMM Aha no worries, and definitely no need to feel dumb, it's super hard to work this stuff out as a beginner. I know from experience :P – Clonkex Jun 25 '17 at 23:11
  • @MMM Well as far as I'm aware, there is no way. The reason is that the browser is directly accessing the file, and there's no way to tell it that `index` is the same as `index.html`. – Clonkex Jun 25 '17 at 23:12
  • Yea, it's quite a lot to learn and I just started this morning since a personal website is going to be my side project this summer (I do C++ development at an internship). Would you recommend me installing apache web servers? For reference, this is for my personal website on github – MMM Jun 25 '17 at 23:13
  • @MMM Well if you're planning on hosting your website from your computer (and you want it to be accessible from over the internet) you'll need to be aware of port forwarding and all that confusing stuff. There's plenty of cheap free webhosting solutions where you can just upload your files and then it's easy to access them. But if you do want to host it yourself, Apache is a good solution. It's pretty easy to get going out of the box too. Just drop your files in `www-data`, if I remember correctly, and then run the server. For testing, miniweb is a great little minimalistic server. – Clonkex Jun 25 '17 at 23:16
  • I see. Thank you so much Clonkex! I will look into hosting this website through Apache :) – MMM Jun 25 '17 at 23:19
  • @MMM No worries at all, glad I could help :) – Clonkex Jun 25 '17 at 23:19
0

.htaccess is used by Apache Webserver. You must install and configure an Apache Webserver and access your site through http://localhost for example.

Currently your .htaccess is completely ignored until your site is served by Apache.

Fabian Barney
  • 14,219
  • 5
  • 40
  • 60