Forums | Mahara Community

Support /
Mod rewrite


anonymous profile picture
Account deleted
Posts: 2

02 November 2010, 14:25

Hello,

What mod-rewrite code do I insert in .htaccess if I want urls to be search engine friendly and show the user's display name?

For example, instead of showing

http://maharasite.com/user/view.php?id=11

How do I show http://maharasite.com/user/miamischools

 

Thanks, your suggestions are appreciated!

Gregor Anželj's profile picture
Posts: 349

03 November 2010, 2:38

I found this (not perfect or maybe it is?) solution:
  1. I've created profile PHP file (without .php extension)
  2. placed it into root htdocs folder
  3. added some lines of code to .htaccess file
That PHP file reads username from PATH_INFO, checks if the appropriate user record exists in usr database and than redirects to appropriate URL address.

E.g.: http://mahara.site.org/profile/bob redirects to http://mahara.site.org/user/view.php?id=3 (if bob's id equals 3 in the database) 

If the user doesn't exists than the script redirects back to the root folder. I don't know what the script should do (where to redirect) if user's profile isn't available to general public?


profile
file (php file without .php extension)
<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    mahara
 * @subpackage core
 * @author     Gregor Anzelj
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2010 Gregor Anzelj, [email protected]
 *
 */

define('INTERNAL', 1);
define('PUBLIC', 1);
require('init.php');

$data = explode('/', $_SERVER['PATH_INFO']);
$userid = get_field('usr', 'id', 'username', $data[1]);

if ($userid) {
    redirect(get_config('wwwroot') . 'user/view.php?id=' . $userid);
} else {
    redirect('/');
}

?>

and changed .htaccess file (changes are marked red)
php_flag register_globals off
php_flag magic_quotes_runtime off
php_flag magic_quotes_sybase off
php_flag magic_quotes_gpc off
php_flag log_errors on
php_flag allow_call_time_pass_reference off
php_value upload_max_filesize 50M
php_value post_max_size 50M

<Files config.php>
    Order deny,allow
    deny from all
</Files>
<Files .htaccess>
    Order deny,allow
    deny from all
</Files>
<Files lib.php>
    Order deny,allow
    deny from all
</Files>

<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None

<Files profile>
    ForceType application/x-httpd-php
</Files>
anonymous profile picture
Account deleted
Posts: 2

24 November 2010, 12:06

Hi Gregor, thanks for this suggestion. I've tried it several times (the profile page without php extension in the htdocs root, and the .htaccess code in the domain top level and at the htdocs root level) but I can't seem to get it work. I am on version 1.3.0rc1... maybe that is the problem...??

Gregor Anželj's profile picture
Posts: 349

25 November 2010, 1:23

I've placed both files (profile php script without .php extension and .htdocs) in the Mahara root folder and it worked for me...

HTH, Gregor

anonymous profile picture
Account deleted
Posts: 92

25 November 2010, 3:28

Hi Gregor,

I also want to change this.

I follow all above steps for implementing the Url.

This is not work for me.

Can you give a idea for that?

anonymous profile picture
Account deleted
Posts: 92

14 December 2010, 0:33

Hello Gregor,

I Hope you are Fine.

Can this functionality is useful for our View making Searchable on Google?

Please Reply for the Same.

Gregor Anželj's profile picture
Posts: 349

14 December 2010, 5:26

I really don't know. I haven't tested it, but I think no.

Regards, Gregor

anonymous profile picture
Account deleted
Posts: 14

01 March 2011, 11:51

Thanks for this. Just put this in our Mahara site. Used 'go' instead of 'profile' but worked great

anonymous profile picture
Account deleted
Posts: 10

26 January 2011, 8:42

I've been trying to get yout code to work with version 1.3.3, but the only thing I get is the following message.I'checked data root diretory and it's writable, the users and permissions are also correct. Any advice?

Mahara: Site unavailable
Your defined data root directory, XXXXXXXXXXXXXXXXXXXXXX, is not writable. This means that neither session data, user files nor anything else that needs to be uploaded can be saved on your server. Please make the directory if it does not exist, or give ownership of the directory to the web server user if it does.

Gregor Anželj's profile picture
Posts: 349

03 March 2011, 6:57

Sorry for late replay... been busy last two months.

I'll look into it in a couple of days...

Regards,
Gregor

10 results