Mod_rewrite question [friendly urls]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Mod_rewrite question [friendly urls]

Post by Todd_Z »

I want to convert

http://www.acdrifter.com/Review/Azumi 2/
to
http://www.acdrifter.com/?page=Review&movie=Azumi 2

I am currently using
RewriteRule ^Review/([^/]*) /?page=Review&movie=$1 [R]

however, this causes a problem -
It redirects the url to the new page, instead of leaving the url in the address bar. If I take out the [R] though, then the basepath is wrong. How do i fix this problem?
User avatar
senthilnayagam
Forum Newbie
Posts: 17
Joined: Wed Jun 08, 2005 5:36 am
Location: Bangalore

Post by senthilnayagam »

If you want a plain PHP based solution

you can find it on experts exchange also(that is me, but yet to get my points)

http://www.experts-exchange.com/Web/Web ... 88785.html

i believe you can manage some PHP, will give you the basic guidelines for you to start

i have done it personally for few big sites

$_SERVER['REQUEST_URI'] will hold the actual script name plus any querystring

use explode using '?' seperate the querystring and SEO URL(we have a reason for us to do it) especially if you use some form which use GET method

with the SEO URL, available now , you can explode it with '/' the seperator and count from left and identify the param you require

In my case it was a MVC framework, where passed the action

sample actions we used were
print : for printer friendly page
pdf: pdf version
mail: mail to friend
story/1-3 : where the main article was split into pages within the cms
buy : ecommerce option

it was a secure setup, and we were able to climb google ranking fast

but for your info, google is learning fast, it manages upto 4 url parameters

Code: Select all

$scriptinfo = explode("?",$_SERVER['REQUEST_URI']);
$params=$scriptinfo[1];// can also be got from $_GET

$userfunction = str_replace($_SERVER['SCRIPT_NAME'],'',$scriptinfo[0]);

if(function_exists($userfunction)){
call_user_func($userfunction, $params);

}else{
echo "invalid function called, possible hack attempt);
//log the error or send mail to you using cutom error handler
exit
}
but under some condition you may need to put some code in .htaccess

regards
Senthilnayagam
Post Reply