Jump to content

Using .htaccess


Recommended Posts

Try Looking here; http://www.faqts.com/knowledge_base/view.phtml/aid/8966

 

Redirect by UserName

When a user logs in the REMOTE_USER environment variable is set and can be read from htaccess. You can use this to redirect users to sub-directories based on their username.

 

RewriteCond %{REMOTE_USER} !^$ [NC]RewriteRule .*index\.html$ /users/%{REMOTE_USER}

Link to comment
Share on other sites

Cheers Rob, that looks exactly what I'm after, but I'm not 100% sure how to use it. I've setup a directory *****/users under which there is a seperate folder for each user with the same name as that user. I've protected /users in Cpanel and added the usernames and passwords, now I presume I have to add something to the .htaccess file in /users but I'm not sure what. Any idea?

 

Cheers

James

Link to comment
Share on other sites

I havent gotten a chance to look into it too much yet but I will say that I dont think I would use it. It may be fine for a few users but if you ever got into the tens or hundreds or more it would be a pain to have to update it whenever a new person comes or someone goes.

 

There are other options using PHP and other scripts that use a database to achieve the same results. I think it would be better to go that route if one has many users that need this feature. Just a few and this should be fine.

Edited by TCH-Rob
Link to comment
Share on other sites

James,

 

I have tried a few various incarnations of that .htaccess option. I can not get it to work properly, I get a page not found or a redirect to the list of folders with usernames.

 

I encourage you to give it a go still if you want, maybe one of the Mikes has a better answer. I found this option by "googleing" redirect users based on username no quotes. There were other options with various scripts. You may want to have a go at that as well.

Link to comment
Share on other sites

I've searched all through the User authentication section of hotscripts.com and there are hundred of scripts to have lots of users able to login to a 'members area', but I can't find any which go to a different page depending on the user.

 

Can anyone help me with this?

 

Cheers

James

Link to comment
Share on other sites

Hi Rob, yeh they work well apart from if someone knows the address of the page they can get to it directly without the username or password. Thats why I like the idea of the .htaccess thing. If you have a chance it would be cool if you could have a look at the .htaccess way of sending a user to their own page. If it looks too complicated then it doesn't matter, and thank you for all your help.

 

James

Link to comment
Share on other sites

My best guess how I'd use it:

 

>RewriteCond %{REMOTE_USER} ^user1$ [NC]
RewriteRule ^.*index\.html$ /user1place
RewriteCond %{REMOTE_USER} ^user2$ [NC]
RewriteRule ^.*index\.html$ /user2place

 

I wouldn't have it autoinsert the user myself, but if you can get that working, more power to you...

 

Disclaimer: I'm not sure if this work, I haven't been able to test it.

Edited by TCH-Robert
Link to comment
Share on other sites

Hi Rob, yeh they work well apart from if someone knows the address of the page they can get to it directly without the username or password.

So send them to /folder/name.htm and .htaccess the folder to only allow users to enter from password page. Like some larger sites do when the issue of deep linking was big, try and get to a deeper part of the site and it redirected you to a main page and you had to go from there.

Link to comment
Share on other sites

Cheers guys, so Robert, I'm not very familiar wi how to use the whole .htaccess thing, which .htaccess file should i put those lines in?

 

Rob, never realised that was possilbe, is it relativly easy to do?

 

Cheers

James

Link to comment
Share on other sites

Lets say your site was like this

 

index - with link to pw protected members area

 

- members folder

 

-- member1 folder

------ member1 index

 

-- member2 folder

 

-- member3 folder

 

If I went to member1 folder/member1 index I will still get the user pw prompt as it is in a folder under the main protected folder. Throw in a redirect on each page that makes them log in at the members link and you can control it pretty well.

 

Get the authentication set up and working so it redirects, I will find you the code to force entry through a specific page.

Link to comment
Share on other sites

Another option may be to have a form, where you have a text box and depending on what was typed in it, when submit was clicked, could be parsed to the URL. That folder would be pw protected for that user. I dont know how to parse a variable into a URL though.

 

I was thinking something like this but it isnt quite right

 

><form action="<?php
echo 'http://www.knifeandblade.com/members/users/,
  urlencode($user) ';
?>"  method="get">
Your Name <input type=text name="user" size=20>
<input type=submit value="Submit" />
</form>

 

Maybe we can get some input from a PHP guru.

Edited by TCH-Rob
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...