Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Use .htaccess to appoint default page for subdirectory


  • Please log in to reply

#1
magusbuckley

magusbuckley

    Member

  • Member
  • PipPipPip
  • 626 posts
Hello to all..

So, here's my story.

I'm building a site and decided to create a custom 404 error page (still in the works). I found documentation that described how to add this page to the .htaccess page. Unfortunately, I assumed the .htaccess page was only used for the 404 error page and so created that file and added that single line of code to reference the 404 page. Then, I published my site, overrighting the .htaccess file that was already in place.

When finished, I headed to my site and got an error (500). A bit further research and I realized in a right quick hurry I had just screwed up by getting rid of that old .htaccess file. I copied a single line of code that got my site working...mostly. I thought all was good but I am still having trouble with pages in subdirectories. Here's an example - I used to visit www.mysite.com/subfolder and a default page for that folder would load like www.mysite.com/subfolder/default_page.html or whatever. Now, when I key www.mysite.com/subfolder, I get the 404 error page. It's as if it's trying to find a page that doesn't exist.

Even stranger, if I type the full path in the address bar www.mysite.com/subfolder/default_page.html, I get another error. I've checked the file on the web server and see that it does, in fact, exist and the code looks fine for that page.

As such, I'm assuming this goes back to me blowing away my .htaccess file. I've been trying to find documentation online, with no luck thus far, that will explain how to set that default_page.html file as the default page for that sub folder.

Any ideas? If not, I really just shot myself in the foot.

Thanks,

Magus
  • 0

Advertisements


#2
AstraNut

AstraNut

    Member

  • Member
  • PipPipPip
  • 465 posts
Since the original rewrite conditions in the .htaccess file are gone, I imagine you'll have to rename the default_page.html file to index.html as that is what file server looks for after www.mysite.com/subfolder/ . Try removing the .htaccess file totally while you work on the problem. If you use a cPanel, or equivalent, you can use it to set the path to all the customized error files. Any change you ran a site backup that's in a compress file?
  • 0

#3
magusbuckley

magusbuckley

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 626 posts
AstroNut - thanks for the quick reply.

After looking at other examples online, I'm realizing that the .htaccess page is full of code. Unfortunately, as I described before, mine now only has to lines of code - one for the 404 page and the other to reference my index page on the root folder. Sigh.

Anyway, back to business.

First - you've asked me to rename the default_page.html file to index.html. I'm not sure if that's possible in my case, but I'll try. Not possible? Well, the problem is that this page was created during an installation routine of a member management program I installed on the web server. It's one of the main pages, containing a form, and the layout comes from a PHP file. I'm guessing renaming that file will "break" some other stuff, if you know what I mean. At the very least, I'd loose my formatting. See, I'm obviously no master web programmer, but I've been creating sites from time to time since FrontPage about 10 or 15 years ago for fun. I learned the Dreamweaver app (CS4) and CSS code just a few years ago. I've never formatted a page in PHP before so if I change the name of my page, I'm not sure how difficult it will be to get that formatting back OR if it will break the forms functionality (wouldn't think so). If it was pointing back to a CSS page, I'd be golden! However, I can give this a shot.

Second - you've asked me to try removing the .htaccess file altogether. Hmm, won't that make matters worse? I wouldn't think anything on the server side would simply recreate this file for me with the correct code - possibly the root folder stuff but certainly not the subfolders. But again, I can try this.

Third - you've asked if I'm using a cPanel or equivalent. To be honest, I've never heard of a cPanel so would have to look that up to know what your talking about. For now, and as I mentioned earlier in this post, I'm really just using Dreamweaver and the member management program (that, of course, is on the server side).

And forth - you've asked if I have a backup of my site. I have backups of backups of backups of the data that's on my local drive, but no backups of anything on the server side. Not sure if my hosting company has a backup button I can use to download a zipped copy of my site, but surely I can connect via FTP and pull a copy down. I suppose I've never thought of that before as I've never made such a mistake as this. I'm guessing you're wondering if I have the old .htaccess file and the answer is no. I already thought of that one as well.


So far, I've learned to add lines of code to the .htaccess page, not replace the entire file and I've learned the importance of backing up the server side files. I screwed up but am learning some things and really appreciate your help thus far.

I won't have time to try any of your methods until later in the week. I have special projects going on at work so won't be able to get into all of this until sometime Friday. Don't worry, I will post the results.

Thanks,

Magus
  • 0

#4
magusbuckley

magusbuckley

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 626 posts
Also wondering this - I added a single line of code that said the index file would be index.html for the root of the site (DirectoryIndex index.htm). Is there not a line of code like this that could be used for subfolders as well (path DirectoryIndex default_page.html "for example")?

But this all makes me worry about all of those other lines of code that are missing and what else could be wrong that I don't even know about. Ha.

Thanks!

Magus
  • 0

#5
magusbuckley

magusbuckley

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 626 posts
SOLVED!!!

Man, I worked all day and have to return in a few hours in the early "A" of "M" for a special project. I should have taken a nap or something but this was driving me crazy and I really wanted to get to the bottom of it. Finally, I have found resolution and will post it here for anyone down the road with an issue like mine.

I am hosting with Godaddy on a Linux box and, after reading replies here, decided to call Godaddy to see if they could restore the .htaccess file. As it turns out, you can restore a file yourself. Simply sign into your account, go to your "Hosting" section and "Launch" the domain in question. Then, go to the FTP manager and in the upper left hand corner, you'll see buttons for "Current" and "History". "Current" is the default choice. Click on "History" and then choose a date on the calendar from the right. When the screen refreshes, you'll be looking at the files on your site as they were on that date. Nice. From there, you can restore an old file.

Fix my problem? NOPE! Why not? There was no .htaccess page before the date I published mine - two days ago. OK, I suppose it's not needed then. I flipped from History to Current and deleted it. A few minutes later, MOST of my site was working again.

I say most because with the .htaccess file gone, how would I enable my 404 error page? And, why in the ^#%$ is my index page not displaying by default? Both were easy fixes, but required research on my part.

You can choose the file you'd like to use as a custom 404 error page from "Settings" in your "Hosting" section. There is actually a button called "404 Error". I mean, how easy is that. No need for that .htaccess after all with them. Any why wasn't my index page working? Well, on a linux box, the default order of pages, or the pages it's looking for to be the default begin with default.htm. That page, default.htm is the first page in your root (of a Linux box) the server is looking for. If it can't find it, it looks for another page, and then another, and then another, until finally it finds your index.htm or index.html page. I actually had a page called default.htm that was published on the same day I published the .htaccess file. And so, each time you went to my site, the server found my unfinished default.htm file and loaded that instead of index.html and then, that .htaccess file I published broke everything else. NICE!!

Anyway, it seems the .htaccess file gives you much control over your site and how it functions but I'm seeing on other sites that Godaddy isn't a fan of customization. Ha.

Hope this helps. Astro - thanks for you help, buddy! :thumbsup:

Magus
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP