Forum Moderators: phranque

Message Too Old, No Replies

Fake subdirectories

how would I make fake subdirectories?

         

s00pcan

7:46 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



Ok here's what I want to do:

[example.com...]
maps to:
[example.com...]

index.php will include the second page and not the first (I already have code for that) if there id2=anything.

What I need is some way to use mod_rewrite to do this. I don't understand the syntax of it so I'm asking for help here.

[edited by: heini at 8:39 pm (utc) on April 12, 2003]
[edit reason] no urls please / thanks! [/edit]

le_gber

8:00 pm on Apr 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi s00pcan and Welcome to WebmasterWorld [webmasterworld.com]

have a look here:
[searchengineworld.com...]

and search for mod_rewrite, there is quite a lot of comprehensive threads explaining how to use it.

Sorry I'm not a PHP/Apache Guru so I can't help you :)

Leo

<added> you might also want to look at this specialised forum [webmasterworld.com], a lot of threads about mod_rewrite were started there.</added>

Birdman

8:34 pm on Apr 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is how I rewrite using mod_rewrite [httpd.apache.org]. Notice the _shop and _info, they help me control which urls I want to rewrite.

The example below should rewrite..

http*//www.site.com/first_id/second_id2

to..

http*//www.site.com/index.php?id=first&id2=second

RewriteEngine On
RewriteRule ^(.*)_id/(.*)_id2$ /index.php?id=$1&id2=$2 [L]

s00pcan

8:50 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



I already have that exact code (minus the _id and _id2), but I also want /first/ to work without a subdirectory. I'm reading the mod_rewrite doc to figure it out.

Birdman

10:08 pm on Apr 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should work but it is probably in your best interest to examine the documentation, as you are doing. Good luck. I use the identifiers(ie. _id) so the rules don't rewrite every request, like:

site.com/images/34.jpg

Without the _id, the above url; would be rewritten to:

site.com/index.php?id=images&id2=34.jpg

RewriteEngine On
RewriteRule ^(.*)_id/$ /index.php?id=$1
RewriteRule ^(.*)_id/(.*)_id2$ /index.php?id=$1&id2=$2 [L]

s00pcan

10:28 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



Haha.. I just made that code after reading the doc (it's really helpful) and was wondering why my pictures weren't working. Since I only have two real directories that isn't a problem once I figure out how to make it ignore them...

s00pcan

12:42 am on Apr 13, 2003 (gmt 0)

10+ Year Member



I've been trying things for hours now and still can't get it to ignore my real directories. This didn't work..

RewriteEngine On
RewriteRule ^/images/(.+) - [PT,L]
RewriteRule ^(.*)/$ /index.php?id=$1
RewriteRule ^(.*)/(.*)$ /index.php?id=$1&id2=$2 [L]

I'm going to go crazy if I don't figure this out.

Birdman

1:14 am on Apr 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you use a unique identifier(Ie. _id) you won't have that problem and you can always add real dirs in the future.

s00pcan

4:10 am on Apr 13, 2003 (gmt 0)

10+ Year Member



RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteRule ^([^/]+)/([^/]+)/$ index.php?id=$2 [L]
RewriteRule ^([^/]+)/$ index.php?id=$1 [L]

This works great, and no ugly _id's!

Birdman

10:49 am on Apr 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm glad you got it figured. In my case the _id is not ugly, it's a keyword ;) No problems there.