473,480 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic directory structures

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
4 5233
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
13263
by: Nancy | last post by:
Hi, When I start my PC(winXP Pro), it always says: Unknown(): Unable toload dynamic library './php_msql.dll' - The specified module could not be found. Then my Apache servre starts, load php...
5
4918
by: Charlie | last post by:
Hi, The description of Python always mentions "very high level dynamic data types". Now, I can't seem to find any examples of these (nothing described with this term anyway). Is this simply...
8
3658
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
10
2049
by: Alan Searle | last post by:
I would like to scan a directory structure into XML to offer navigation functionality in HTML / XSL pages. My questions are: 1. Which is the best structure to store variable depth heirarchies...
23
7363
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
5049
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
1
2304
by: Gurur | last post by:
Hi all, I have a doubt. If I have 2 structures and one is parent of other , ie the child structure is present in the parent one . And if the child structure is declared as dynamic array in the...
6
2248
by: gunjan29484 | last post by:
Hello, i want to compare the two directory structures and find out if any file or directory is missing in the second directory structure or not. (directory1 is a super set of directory2) I have...
5
2571
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7059
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3011
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.