|
|
|
|
![]() ![]() |
Oct 26 2007, 04:33 AM
Post
#1
|
|
|
Premium Member Group: [HOSTED] Posts: 274 Joined: 17-June 07 From: Tasmania Member No.: 22,699 |
Hi
Is it possible to set up a script somehow, where you go to www.domain.com/directory/directory1, ecxept you can relace directory1 with anything, and it will run the same script, whether a directory called directory1 exists in the folder directory or not? Say, for example, you go to www.domain.com/directory/Hello and a page comes up that says "Your text: Hello", even though a "Hello" directory doesn't exist? I can think of no way of doing this with PHP, and the only way I can think of being able to do it is with serverside scripting that you obvioulsy wouldn't be able to do with a hosting account. The other way of doing something like this, which I think you might be able to set up via cPanel (Although I don't know how), is set up a script so that whenever someone tries to access the directory "directory", it checks to see if they're tring to access another directory inside that, and if they are, create that directory, so they can access it, and then destroy it later. Can anyone help? |
|
|
|
Oct 26 2007, 06:49 AM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 372 Joined: 16-February 06 From: Kolkata, India Member No.: 11,322 |
PHP is a server side scripting language. I suppose you can use mod rewrite in .htaccess file to redirect any such path to a PHP file, with the directory name as the input, say www.domain.com/directory/?directory=directory1
I am not much aware of Linux and the htaccess magic, but I do believe this could be done. |
|
|
|
Oct 26 2007, 06:54 AM
Post
#3
|
|
|
Oh come on Mrs. B! Group: Members Posts: 648 Joined: 6-June 07 From: Tasmania, Australia Member No.: 22,422 |
well jay u no that it can be done cos other fansites do it.
and it works for everyone u type in not just members. you could ask other fansites about what they did about it or ask on habbos.net |
|
|
|
Oct 26 2007, 08:50 AM
Post
#4
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,002 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
Just as turbopowerdmaxsteel said, .htaccess is all you need
CODE RewriteEngine on RewriteRule ^directory/(.+)$ /directory/script.php?directory=$1 Regular expression, which are used in .htaccess files, might be confusing in the beginning, but they are an extremely powerful tool. ^directory/(.*)$ will match all the URLs which start with www.domain.com/directory/ and end with any text, which we capture with the use of paranthesis - the dot signifies any character, and the plus sign means "one or more of the previous" (which is in our case any character). After that, we just use $1 as a reference to the first thing we captured, or in other words the .+ part. After that, it's all PHP. |
|
|
|
Oct 27 2007, 03:33 AM
Post
#5
|
|
|
Premium Member Group: [HOSTED] Posts: 274 Joined: 17-June 07 From: Tasmania Member No.: 22,699 |
Thanks. I'd never taken much notice of the .htaccess files, I never realised they did anything, lol.
Perhaps I should have a look at what other things .htaccess can do. Edit: Ok, my .htaccess file looks like this: CODE # -FrontPage- IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* <Limit GET POST> order deny,allow deny from all allow from all </Limit> <Limit PUT DELETE> order deny,allow deny from all </Limit> AuthName habble-aus.com AuthUserFile /home/habbleau/public_html/_vti_pvt/service.pwd AuthGroupFile /home/habbleau/public_html/_vti_pvt/service.grp RewriteEngine on RewriteRule ^profiles/(.*) profiles/index.php?name=$1 What this should do, is (say) if I go to profiles/abc, it should go to profiles/index.php?name=abc. But it isn't. It seems to be going to profiles/index.php?name=index.php Um, Can anyone help this time? This post has been edited by Habble: Oct 27 2007, 07:22 AM |
|
|
|
Oct 27 2007, 08:27 AM
Post
#6
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,002 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
Try this instead
CODE RewriteCond %{REQUEST_URI} !^profiles/index.php [NC] RewriteRule ^profiles/(.*) profiles/index.php?name=$1 I'm not that good when it comes to .htaccess, but it seems to me that you must prevent redirection when (.*) is index.php?name=... |
|
|
|
Oct 27 2007, 08:37 AM
Post
#7
|
|
|
Premium Member Group: [HOSTED] Posts: 372 Joined: 16-February 06 From: Kolkata, India Member No.: 11,322 |
Suppose you go to the path profiles/abc, due to the RewriteRule, the internal URL would be profiles/index.php?name=abc. Again, this URL matches the condition you specified in the RewriteRule ^profiles/(.*). So, the new URL becomes profiles/index.php?name=index.php.
Instead, use the following code. It redirects the URL only when the part after profiles/ contains a-z, A-Z and 0-9 characters. You can modify the code to include other characters like _ and - . Just don't allow the dot character in the username. CODE RewriteRule ^profiles/([a-z,A-Z,0-9]+)$ profiles/index.php?name=$1
|
|
|
|
Oct 28 2007, 02:27 AM
Post
#8
|
|
|
Premium Member Group: [HOSTED] Posts: 274 Joined: 17-June 07 From: Tasmania Member No.: 22,699 |
Thanks! I've got it working using pyost's script. The finished thing now looks like this:
RewriteEngine on RewriteCond %{REQUEST_URI} !/profiles/index.php RewriteRule ^profiles/(.*) profiles/index.php?name=$1 |
|
|
|
Oct 28 2007, 03:27 AM
Post
#9
|
|
|
Oh come on Mrs. B! Group: Members Posts: 648 Joined: 6-June 07 From: Tasmania, Australia Member No.: 22,422 |
when i go to a profile that isnt a habble member, all i get is the users hotel is offline.
i gather its not meant to work yet cos also the different countires and that. |
|
|
|
Oct 28 2007, 05:56 AM
Post
#10
|
|
|
the Q Group: [HOSTED] Posts: 1,022 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 |
Another way to do it is to use in php $_SERVER['PATH_INFO']; in that way you can get values from index.php/directory1/value2 or anything you like, moreover if you don't like seeing index.php in the url line, then you also can use .htaccess to make it look like /directory1/value2 and use the same PHP stuff, in this case, the mod rewrite will be much easier.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 6th September 2008 - 06:33 PM |