Mod_Rewrite
 
Notifications
Clear all

Mod_Rewrite

2 Posts
2 Users
0 Reactions
1,709 Views
(@tomas1402)
Posts: 16
Active Member
Topic starter
 

In English:

I would like to make the mod_rewrite I make the addresses of users to www.sitio.com.ar/ ~ user, such as those of FF.net.
I searched information, but can not make it work. Does anyone could help me?

As of now, thank you very much.


En español:

Me gustaría lograr que el Mod_Rewrite me hiciese las direcciones de usuarios a www.sitio.com.ar/~Usuario, como las de FF.net.
Yo Busqué información, pero no logro hacerlo funcionar. ¿Alguien podría ayudarme?

Desde ya, muchas gracias.


 
Posted : 27/05/2008 8:26 pm
(@Seiji)
Posts: 0
 

I know you've posted it long ago but I'll try to answer your question.

mod_rewrite it's good because makes the URL fancy 😀
EDIT: Never really looked into mod_rewrite, looks like all you need it's to use some regex and the script will keep getting all the $_REQUESTS. For user's profiles, you need to give the id at the url, like this: http://www.myefictionsite.com/u/123/user_penname

You can try to make redirections and includes for some pages, like the users profiles. I'll give you some clues of how to do it.

First you need to tell apache to redirect all errors to a single php file, this one will get what the user is trying to see and display it.
To make it work you will need to explode the slashes and check, but if you allow users to have some special characters for pennames this can be tricky. I've created a field in authors table that will hold the safe characters penname of the user, this makes things faster. Bellow it's an example of how to do it, but it's  just some code to give you some directions, will not work alone.

Penname = José Araújo 
Penname_url = jose_araujo

URL = www.myefictionsite.com/user/jose_araujo


$url = $_SERVER['REQUEST_URI'];
$strings = explode("/", $url);

require("includes/corefunctions.php");

//this one will hold what the user wants to see... an user page? A story?
$string1 = addslashes(descript($string['1']));

//now this one will have the id of it, in this case, the penname
$string2 = addslashes(descript($string['2']));

//checks if the the page it's a profile
if ($string1 == "user") {
$query = mysql_query("SELECT uid FROM fanfiction_authors WHERE penname_url = '$string1' LIMIT 1");
$numrows = mysql_num_rows($query);

//if we have someone with that penname, get the ID and require the page
if ($numrows > 0) {
$userfound = mysql_fetch_array($procura_nome);
$uid = $userfound['uid'];
header("HTTP/1.0 200 OK");
require ("viewuser.php");
exit();
}
else {
echo "Page not found";
}
}

else {
echo "Page not found";
}

You can try to to it in an easier way, instead of pennames at the url you can get only the ids number. Like www.myefictionsite.com/user/347
There's no need for an extra field at DB, just check if strings[2] it's a number and get the user with that ID.

You can use it with stories too, like this: www.myefictionsite.com/story/635/my_first_story
You don't need to check the story's title, just get the story with that ID.

I did something like this for user's profiles, a live demo here:
http://fanfiction.nyah.com.br/seiji_mad_dog

Oh! Up there I included the corefunctions.php file, if u do the same you need to change somethings in efiction or you will include the same file twice.

Edit: Forgot to say, "José Araújo" and "José_Araújo" are different pennames but may result in the same url for penname since spaces are converted to underlines. You may need to block pennames that are almost the same, like the example I gave... or you can replace spaces with "%20" and have less problems ^^"
Like this:

Penname: José Araújo
Result: www.myefictionsite.com/jose%20araujo

Penname: José_Araújo
Result: www.myefictionsite.com/jose_araujo

Well... I hope it helps, to make it work you will need some php & mysql skills. Good luck!

Seiji.


 
Posted : 05/07/2008 12:36 am
Share: