By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Dynamic directory structures

P: n/a
Hi!

I need to translate the path

/category_name/sub_category_name/

to

/category.php?sub_category_id=2

without redirecting the user.

There seem to be many ways of doing it, but with my current web hosting
provider (E.N.E IT - www.eneit.com) there are some constraints. For example
I cannot modify the httpd.conf.
However, I've got the functionality provided by CPanel (e.g. AddHandler's)
and I can create .htaccess files.

I've read a little about the RedirectRule command in Apache, but it does not
seem to work due to that I'm on a shared hosting server.

I've also realised that I could do
/category.php/category_name/sub_category_name/, but haven't found a way to
remove the .php in that instance.

I'm basically looking for the most basic solution...

All the best,

Erik Andersson
http://www.wcttour.com/
- Everything from the World Pro Surfing Championships, WCT.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
As far as I know, to be able to do
/some_php_file_that_doesnt_end_in_.php/blah/blah/blah, you need to have
mod-rewrite installed for apache. (Of course, if you do
/somefile.php/whatever/whatever that's easy enough to parse out using
query_string. but for not having blah.php/whatever, I am pretty sure apache
needs to be configured with mod-rewrite. Sorry :( I hope I'm wrong, but I
don't think so...

Erik Andersson wrote:
Hi!

I need to translate the path

/category_name/sub_category_name/

to

/category.php?sub_category_id=2

without redirecting the user.

There seem to be many ways of doing it, but with my current web
hosting provider (E.N.E IT - www.eneit.com) there are some
constraints. For example I cannot modify the httpd.conf.
However, I've got the functionality provided by CPanel (e.g.
AddHandler's) and I can create .htaccess files.

I've read a little about the RedirectRule command in Apache, but it
does not seem to work due to that I'm on a shared hosting server.

I've also realised that I could do
/category.php/category_name/sub_category_name/, but haven't found a
way to remove the .php in that instance.

I'm basically looking for the most basic solution...

All the best,

Erik Andersson
http://www.wcttour.com/
- Everything from the World Pro Surfing Championships, WCT.

Jul 17 '05 #2

P: n/a
Erik Andersson wrote:

Hi!

I need to translate the path

/category_name/sub_category_name/

to

/category.php?sub_category_id=2

without redirecting the user.

There seem to be many ways of doing it, but with my current web hosting
provider (E.N.E IT - www.eneit.com) there are some constraints. For example
I cannot modify the httpd.conf.
However, I've got the functionality provided by CPanel (e.g. AddHandler's)
and I can create .htaccess files.

I've read a little about the RedirectRule command in Apache, but it does not
seem to work due to that I'm on a shared hosting server.

I've also realised that I could do
/category.php/category_name/sub_category_name/, but haven't found a way to
remove the .php in that instance.

I'm basically looking for the most basic solution...


I recently did this on a couple webpages. Now my dynamic pages are being
crawled by Google (which was why I did it).

I wrote a .htaccess file with the following in it:

Redirect 301 /misc_fark.php http://www.glassgiant.com/misc_fark/
Redirect 301 /gb_view.php http://www.glassgiant.com/gb_view/
Redirect 301 /misc_gallery-album.php http://www.glassgiant.com/misc_gallery.php
<Files misc_gallery-album>
ForceType application/x-httpd-php
</Files>
<Files misc_fark>
ForceType application/x-httpd-php
</Files>
<Files gb_view>
ForceType application/x-httpd-php
</Files>

Then I changed the names of the files to leave off the .php (so it looks like a
directory). Note: the redirect statements are there to help the search engine
find the new pages and to point people following old links to the right
location.

Then I exploded the $_SERVER['REQUEST_URI'] into an array using "/".

Now, instead of using $_GET['id'] on page http://mydomain.com/misc_fark.php?id=3
I use $myarray[2] on page http://mydomain.com/misc_fark/3/

This is not the ideal situation, but it works well and is much easier than
messing around with mod-rewrite. It does require that you can make your own
..htaccess, though. But if you can't, chances are you don't have access to
mod-rewrite either. You may have a .htaccess file already - make sure you don't
overwrite it if you do.

PS - Looking at the .htaccess file above, it occurs to me that I could probably
include all the files to ForceType in a single Files tag, but I'm not sure.

Good luck,
Shawn

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3

P: n/a
"Erik Andersson" <er**@wcttour.com> wrote in message news:<3f*********************@uq-127creek-reader-01.brisbane.pipenetworks.com.au>...
Hi!

I need to translate the path

/category_name/sub_category_name/

to

/category.php?sub_category_id=2

without redirecting the user.


I duct tape sorta way of scripting would be to add this to your
..htaccess file

Alias /category_name/sub_category_name/
/webhostingdir/youraccount/www/

then in your index.php you can do something like this, you may have to
play with the list/split (its 4:00am for me, and I have programmers
deliria)

$url = $_SERVER['SCRIPT_NAME']
list($n,$cat,$subcat) = split("/",$redir);
$inc = "http://www.mysite.com/$cat.php?sub_category_name=$subcat";
$page = virtual($inc);
print $page;
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #4

P: n/a
Ok, I got a simple set up that works, I just tested it,

in your .htaccess file add this
ErrorDocument 404 /dynpage.php

and the dynpage.php reads as follow
<?php

$r = $_SERVER['REQUEST_URI'];
list($n,$page,$sub_category_id) = split($r);
// note $sub_category_id is already set now, so dont look for it with a
$_GET
include("$page.php");
?>

You can see a funky example at http://findit.myhq.info/cars/trucks

--
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.