folder/485 not folder/?id=485

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

folder/485 not folder/?id=485

Post by phice »

I'm looking for something that will allow the id=485 translate into a folder lookalike in the address bar.

In example, I've got a post #930. Normally, we'd use "/ReadPost.php?id=930", but I want "/930" instead. deviantArt uses this for their forum, and I'm wondering how they accomplished this.
Image Image
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

use a script as the 404 Error handler (not found), defined in .htaccess if you are using a default Apache setup
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

$id = $_POST['id'];
$id = "/".$id;
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Stoker wrote:use a script as the 404 Error handler (not found), defined in .htaccess if you are using a default Apache setup
Then that would put tremendous strain on my Error logs.
Image Image
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

I think that's how they do it, you can define away some log-options or perhaps some other apache-config settings that will call one file for any url..

There is no way to do this by scripting alone, as it is the webserver that reads the path and loads files accordingly..
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

for apache: if a handler is found everthing after is passed to this handler.
create a new directory (e.g. test)and place a .htaccess and a file called script in it.
content of .htaccess

Code: Select all

ForceType application/x-httpd-php
content of script

Code: Select all

<html><body>
<table>
<?php
$n = array('QUERY_STRING', 'REQUEST_URI', 'SCRIPT_NAME', 'PATH_INFO', 'PATH_TRANSLATED', 'PHP_SELF');
foreach($n as $e)
	echo '<tr><td>', $e, '</td><td>', $_SERVER[$e], '</td></tr>';
?>
</table>
</body></html>
now call this script e.g. by http://a.ho.st/test/script/something123
Providers can disable this option, so it might not work.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

that's a cool approach, didnt think about that one..

I am not sure why I didn't think about it at first; mod_rewrite - I believe that is the most common way for many scripts, just rewrite the url's matching a certain pattern/path to the script..
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Well that didn't work.

Remember that I'm not in full control of the webserver. I've only got a shared-hosting service.
Image Image
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Did you try mod_rewrite? most web hosts have that..

http://www.webmasterbase.com/article/910

something like

Code: Select all

RewriteEngine On 
RewriteRule /myforum/(*) /index.php?thepath=$1
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

better use 'RewriteRule /[0-9+] /index.php?id=$1' just to be safe... learn abotu regexp, it's your friend.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

I am not that familiar with mod_rewrite but I assume that you need grouping to use $?

RewriteRule ^/([0-9]+) /index.php?id=$1
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Would I place this inside the .htaccess? And, if so, which folder should I place it in? / or /boards/?
Image Image
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

in a .htaccess file yes, location depends on where you want the rule(s) to apply, you can move the file and/or you can change the matching pattern .. take a look at the link I posted above to get a better understanding of how mod_rewrite works..
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post by superwormy »

<FilesMatch "^scriptnamewhichlookslikeafolder$">
ForceType application/x-httpd-php
</FilesMatch>
Post Reply