The URL mod problem evolves... your examination appreciated

Discuss practical ways rearrange URLs using mod_rewrite.

The URL mod problem evolves... your examination appreciated

Postby cro_mod » Wed May 21, 2008 6:56 am

Thank you.

I have a PHP file which contains script that reads the URL and and then pulls out the appropriate page from a database. Currently that PHP file has to be in the URL, like this >>

http://www.librarydynamo.org/read.php/events/home

With the .htaccess file forcing read to be sent through the PHP processor.

I want to get rid of the read.php from the URL but force the browser/server to process the read.php file, which would examine the URL and send the URL directories through a script.

For examples:
http://www.librarydynamo.org/events/home
http://www.librarydynamo.org/articles/wash_post_2_2_08
http://www.librarydynamo.org/dynamos/shaw/calendar/home

Anytime one of these URL's are searched for, it automatically sends all directories after the domain name into the script found in the read.php file.

/events/home
/articles/wash_post_2_2_08
/dynamos/shaw/calendar/home
/x/y/z/a/b/c/~
whatever/whatever/whatever/

The read.php script would take the above retrieved info and process it using a php GET statement like /read.php?url=/events/home

The trick I'm seeking help with is how to I have my .htaccess file take any URL and send it through the script.

I keep getting a page that says Internal Error. Here's is my current .htaccess file >>

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /read.php/$0

---

Am I totally clueless here... I really just tried to piece together what I've seen in other posts and really don't have a good understanding of these rules.

Any help you can provide would be most appreciated.

Chris O.
Last edited by cro_mod on Thu May 22, 2008 8:28 pm, edited 1 time in total.
cro_mod
 
Posts: 2
Joined: Wed May 21, 2008 6:51 am
Location: Washington, DC

Postby richardk » Thu May 22, 2008 2:19 pm

The read.php script would take the above retrieved info and process it using a php GET statement like /read.php?url=/events/home

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /read.php?url=/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Here's a nuance to this issue

Postby cro_mod » Thu May 22, 2008 8:28 pm

Thank you, yes your code seemed to work. Now to add a nuance.

For whatever reason... my original .htaccess file which forced "read" to be processed as a PHP file also allowed for me to add variables through the Get method... it just worked so I went with it.

For example, when a user is logged in and they click on an admin function anywhere in the site, the following example URL would be initiated and the read.php script would work >>

http://www.districtdynamos.org/read.php ... e=standard
(this is just an example URL, it could be any set of directories plus the variables)

So now the questions gets trickier... using the .htaccess you helped me with to read the URL directories after the domain, I'm wondering if the .htaccess can it also append any variables as shown above.

So here's my .htaccess now >>

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /read.php?get_urlpath=/$1 [QSA,L]

This .htaccess will help me get take the following URL and put it into a Get variable like this...

http://www.districtdynamos.org/publications/home
will become
http://www.districtdynamos.org/read.php ... tions/home

HOW CAN I HAVE HTACCESS DO A LITTLE MORE FOR ME AND TAKE THIS URL >>

http://www.districtdynamos.org/publicat ... e=standard
to become
http://www.districtdynamos.org/read.php ... e=standard

Your help is most appreciated!

Chris
cro_mod
 
Posts: 2
Joined: Wed May 21, 2008 6:51 am
Location: Washington, DC

Postby richardk » Sun May 25, 2008 10:14 am

The QSA flag should be doing that.

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule wrote:'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 111 guests

cron