Jump to content

mod rewriting - is this possible?


redbullmarky

Recommended Posts

Hi all

Just wondering about mod rewrite. i've actually used it on sites before to provide users with their own homepage - eg so they can type [a href=\"http://www.mysite.com/users/redbullmarky\" target=\"_blank\"]http://www.mysite.com/users/redbullmarky[/a], which would get resolved to something like [a href=\"http://www.mysite.com/users/index.php?user=redbullmarky\" target=\"_blank\"]http://www.mysite.com/users/index.php?user=redbullmarky[/a].

now - i have a situation i want to find out more about.
on a site i'm doing at the moment, i need to refer to the username from the ROOT - ie, www.mysite.com/redbullmarky. also, each user will have sub-pages, so i can type in www.mysite.com/redbullmarky/mypage.

now - how can i keep these usernames safe from actual directories that exist? ie, what if someone sets their username as 'images', etc?

the only way i can think of is to check for URL's that do not have a 'php' or 'htm' extension, and then treat these like users. or worse still, using a custom 404 page to take a user to a page which deals with sending them to the correct place, in the event of anything typed in the URL.

can anyone advise the best way to do this? basically so my usernames do not clash with my directories and files?

cheers
Mark
Link to comment
Share on other sites

I can't help you with mod rewrite stuff so I'll suggest an old-fashioned method.

Presumably before a prospective user can have their own username, their choice needs to be checked to ensure it does not already exist. So, if I had a list of users and included imaginary users named images, includes, etc. wouldn't that achieve your objective?
Link to comment
Share on other sites

[!--quoteo(post=384410:date=Jun 16 2006, 01:12 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 16 2006, 01:12 AM) [snapback]384410[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I can't help you with mod rewrite stuff so I'll suggest an old-fashioned method.

Presumably before a prospective user can have their own username, their choice needs to be checked to ensure it does not already exist. So, if I had a list of users and included imaginary users named images, includes, etc. wouldn't that achieve your objective?
[/quote]

yeah - that bit i understand. the thing that is kinda getting me confused right now is that on a site i'm rewriting, i can literally type in: www.mysite.com/images and it will provide a page that says 'the user "images" does not exist'. even thought the images directory actually does exist, it seems to ignore it and deal with usernames, etc, as priority.

biggest prob is that talking to the old programmer is not possible and (going by the rest of his code) would not be practical. i have access to the site that currently does it via FTP, only i cannot find a htaccess file or anything else to give away the trick.

so in that respect - i'd love it (if they really wanted to) for a user to be able to call themselves 'images', 'includes', 'scripts' or any other stuff, but it's kinda proving a little tricky.

Cheers
Mark
Link to comment
Share on other sites

You might get some REAL help if you would post..umm...idk...perhaps, a .htaccess file or whatever your using to re-write the urls? It ishard to see what you are doing wrong if we don't know how the mod_rewrite is acting. [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]
Link to comment
Share on other sites

Hi Ronald

i'm actually hoping to get a view pointers before i start working out the regex bits, etc, and putting it together.
Like i say, i've done it in subdirectories (www.mysite.com/users/redbullmarky) but never the root - and as their are so many other files and directories, i dont want any clashes.

can you give me any idea of how you would go about doing this? ie, giving a user their own 'virtual directory' with virtual subdirectories within them?

Cheers
Mark
Link to comment
Share on other sites

Sure. Here is how I would do it:

1) Insert folders you will be using (images, includes, headers, config, anything really that shouldn't be a user name but what you might use for directory organization) as usernames into your member table. Meaning make a member called images or whatever and give that user ZERO permissions. Then when a visitor tries to register, they can't have that username.

2) Next you will want to use mkdir() function. Use that function so when a user registers it will make a direcotry for them:
[code]
$username = //  The name they want to register with.

// Be sure to add an error check here to see if the username exist. If it does use exit();
// That will keep the mkdir function from making the directory anyways.

// Example is mkdir("/path/to/my/dir", 0700);
// So you would go

mkdir("/path/to/my/$username", 0700);
[/code]
So it took the username they wanted, checks it first, and if it passes will create the url when $username is set to ronald:
[a href=\"http://www.site.com/path/to/my/ronald\" target=\"_blank\"]http://www.site.com/path/to/my/ronald[/a]

3) Then you are done. Not once do you ever have to mess with .htaccess and the database for the users.

Suggestion. You would have to give users ftp access to their directory ONLY! There is php functions that can make automatic ftp privs. but here is a better suggestion. PHPNuke does this, so you might want to pick it up and see how it works. But create a User Control Panel for the user, a simple code will work that is repeated in eachs users directory. Anyways, create the control panel to make it where they can add files to their directory and take them away. Not once do you EVER have to give them ftp access. The ftp access is contained within the CP code and all they are doing is using the provided access to create files for their dir. Kinda like WYSIWYG editor.

Again, this is how I would do it. It is a lot of work, true, but you come out in the end learning ALOT of stuff. Few people know how to use php to ftp and all that jazz. If you learnt that you would know alot more than most do about php.
Link to comment
Share on other sites

unless i'm missing your point, i dont actually want the user to physically have their own directory/subdirectory.

rather:

[b]http://www.mysite.com/redbullmarky[/b]

would resolve to:

[b]http://www.mysite.com/users/profile.php?user=redbullmarky[/b]

and

[b]http://www.mysite.com/redbullmarky/thisone[/b]

would resolve to

[b]http://www.mysite.com/users/profile.php?user=redbullmarky&section=thisone[/b]

whilst i kinda know how to do the above, what i'm unsure on is if i DID want to allow a user called 'images', etc, etc.

i've thought it through and am almost certain that mod_rewrite in a htaccess would be my solution, but as i'm working from the root directory, with so many files/folders, etc to clash with, was just wondering if i can get away with this - have my cake and eat it - let a user call themselves 'images' if they want, but without affecting things when i'm referring to the 'images' directory for real.

any thoughts?
cheers
Mark
Link to comment
Share on other sites

that could work also. The only problem is that would it show up like that when he list the member names in a Memberlist? It might start looking kinda odd to do that, but if it is a smaller site it would be okay.

Another suggestion would be to make your directories like that instead.

/~images/
/~includes/

and so on.
Link to comment
Share on other sites

[!--quoteo(post=387489:date=Jun 24 2006, 12:17 PM:name=steelmanronald06)--][div class=\'quotetop\']QUOTE(steelmanronald06 @ Jun 24 2006, 12:17 PM) [snapback]387489[/snapback][/div][div class=\'quotemain\'][!--quotec--]
that could work also. The only problem is that would it show up like that when he list the member names in a Memberlist? It might start looking kinda odd to do that, but if it is a smaller site it would be okay.

Another suggestion would be to make your directories like that instead.

/~images/
/~includes/

and so on.
[/quote]No, it wouldn't show up like that on a member list. You'd just search specifically for the part after the symbol used.
Link to comment
Share on other sites

[!--quoteo(post=387779:date=Jun 25 2006, 04:38 PM:name=Eric_Ryk)--][div class=\'quotetop\']QUOTE(Eric_Ryk @ Jun 25 2006, 04:38 PM) [snapback]387779[/snapback][/div][div class=\'quotemain\'][!--quotec--]
No, it wouldn't show up like that on a member list. You'd just search specifically for the part after the symbol used.
[/quote]

good suggestions, chaps. thanks for your help!
If there are any alternatives, I'd still be keen to hear them, but using the ~ for directory names would help a good deal

Cheers
Mark
Link to comment
Share on other sites

[!--quoteo(post=387785:date=Jun 25 2006, 04:53 PM:name=redbullmarky)--][div class=\'quotetop\']QUOTE(redbullmarky @ Jun 25 2006, 04:53 PM) [snapback]387785[/snapback][/div][div class=\'quotemain\'][!--quotec--]
good suggestions, chaps. thanks for your help!
If there are any alternatives, I'd still be keen to hear them, but using the ~ for directory names would help a good deal

Cheers
Mark
[/quote]

Hi
Just wanna clear up with one more question. Aimed at anyone who's got a myspace profile.

How do you reckon they do it?

They have an 'index.cfm' to drive most of the content, which would be easy enough to work around on its own.
They also have 'misc', 'images' and 'modules' directories from what i can see, all with no special characters in their name.

Would I be right in guessing that you could have a list of rules that check each of my 'built in' directories one by one, and if found, stops processing any more rules - then as the last rule, redirect anything else to a page such as '/people/profile.php?user=redbullmarky' ?

If so, and if that's possible, could you possibly provide me a little example or provide a link of a good tutorial? the stuff i've done in the past has been relatively simple stuff, so i'm a little dazed...

Cheers
Mark
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.