Forum Moderators: phranque

Message Too Old, No Replies

rewrite directory to single php file

         

rootsical

8:24 pm on Oct 17, 2009 (gmt 0)

10+ Year Member



hi there.

i am trying to write a directory called audio to a single file called audio.php which will handle.

my server is structured like this:

root/mysite/audio and my htaccess file i have put in the mysite directory.

the audio.php file is located in root/mysite/audio/audio.php .

basically when someone requests for example:

mysite/audio/name-of-audio-request that they actually get served the mysite/audio/audio.php page.

I hope that makes sense...

could anyone look at the code i have tried and tell me what I am doing wrong as it doesn't work at the mo?

htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/audio/*
RewriteRule ^audio/*$ /audio/audio\.php [L]

g1smd

12:19 am on Oct 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'll guess the * and $ needs to be deleted at the very least.

rootsical

12:57 am on Oct 18, 2009 (gmt 0)

10+ Year Member



brilliant, i'll try a few more combinations with that in mind. thanks very much for your help.

rootsical

1:15 am on Oct 18, 2009 (gmt 0)

10+ Year Member



Now going with this, but it still doesn't work.. I'll keep on looking..

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/audio/
RewriteRule ^audio/? /audio/audio\.php [L]

rootsical

1:30 am on Oct 18, 2009 (gmt 0)

10+ Year Member



i couldn't solve it so now i am just going to use a query string technique which i found works..

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^audio/([^/\.]+)$ audio/audio.php?item=$1 [L]

jdMorgan

2:05 am on Oct 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted...

You don't need to escape the period inside the [group], as periods are taken as literals in grouped alternates.

Jim

g1smd

9:46 pm on Oct 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might want to next consider adding a 301 redirect such that if anyone asks for example.com/audio/audio.php?item=something they are redirected to the canonical URL you want them to see.