views:

46

answers:

2

So I learned from this handy guide how to use .htaccess to redirect pretty URIs like foobar.com/baz to specific content that may reside at foobar.com/bazheader345.php?user=baz.

What if I'd like to do the opposite? My anchors are static but I have a lot of content in different files - and none of them has a particularly pretty name. Say I have a page at foobar.com called 123.html and would like the location bar to remain http://foobar.com despite the navigation between files that the user does.

Can this be done via changes to .htaccess? Or simply Javascript?

If it is possible, would it interfere with the browser's history states?

+2  A: 

This is really easy to do with HTML frames. Let's say your home page is http://example.com/index.html. Save index.html as home.html and save something like the following in index.html:

<html>
  <head>
    <title>Website title</title>
  </head>
  <body>
    <iframe src="home.html" width="100%" height="100%" frameborder="0" scrolling="no" />
  </body>
</html>

If you don't want to rename your original home page, you could instead stick a DirectoryIndex directive in your .htaccess file. Just save the above code in, say, frame.html, change home.html to whatever filename your index is at, and add:

DirectoryIndex frame.html

to your .htaccess file.

However, you should know that this practice fell out of style over 10 years ago because it has inherent problems. It won't break your history, but it breaks deep linking (that is, one can't bookmark or link to anything other than the home page).

More info:

Mark Trapp
I agree. While maintaining a consistent URL is more or less possible, it is not normally a good idea.
Peter Wagenet
+2  A: 

You would be much better off creating pretty names for all those other pages, so that you allow your users to link to or bookmark those other pages.... or keep the ugly urls and don't worry about it.

Keeping the same url and displaying different content defeats the entire purpose of a URL, which is to be a unique address for a specific set of information.

Peter Ajtai
I accepted Mark Trapp's answer for posterity, because it provides a method to achieve the goal in question, however, for the record, you are right.
Isaac Lubow