Forum Moderators: open

Message Too Old, No Replies

.htaccess rewrite rule for hiding directories

directory hiding

         

shaggy2442

11:27 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



Hello,

I have a small issue that I am trying to figure out and for the life of me I just can not seem to find the answer.

I am working on a project that ties a few different technologies together for 1 social networking platform that I am building. What I am trying to accomplish is how to hide the directory structure from site visitors and give the members of the site a clean url to go to.

For example the home page for the site members is currently setup like this:

http://www.example.com/ss/user/username

I am trying to figure out a way so that the users can get a clean url that would eliminate the /ss/user/ and look like this:

http://www.example.com/username

I not even sure if this is possible with .htaccess.

Has anyone ever accomplished this/and if so how?

Any help/insight would be greatly appreciated.

[edited by: incrediBILL at 2:26 am (utc) on Nov. 29, 2009]
[edit reason] Use example.com only please [/edit]

jdMorgan

12:55 am on Nov 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is not one of .htaccess or any other 'technology' limitation.

The problem is, how do you know that the username is a username, and not a directory or a filename?

Another problem is preventing users from getting cute and signing up with a username of "robots.txt" or "sitemap.xml" or "favicon.ico" -- That is, how do you prevent "collisions" between usernames and the names of resources required (both now and in the future) for your site to function?

The 'safest' alternatives are to use at least one "directory level" in the URL like example.com/users/<username>/<resource>, or to put all of the "user stuff" into one or more subdomains, e.g. users.example.com/<username>/<resource> or even <username>.example.com/<resource>
(In these examples, <resource> is just the filepath/name of any user-generated content -- stuff that belongs to that user.)

At any rate, the key is to 'make space' for the user-generated URLs so that any "collisions" with the site infrastructure's URL-space can't happen.

After deciding on a method like one of those described above, a bit of URL-to-filename mapping (see Apache mod_rewrite) is all that's needed.

Jim

shaggy2442

1:13 pm on Nov 29, 2009 (gmt 0)

10+ Year Member



Hi Jim,

Thank you for the insight here and yes this all makes sense, I went ahead and took your advise and created a sub domain and copied over all the scripts to the sub domain. I am still unsure how to go from: sub.example.com/ss/username to sub.examplePl.com/username.

It would be great if I could take that a step further using the mod_rewrite to do: example.com/username

[edited by: incrediBILL at 9:25 am (utc) on Nov. 30, 2009]
[edit reason] Please use Example.com only [/edit]