myspace like - Mod rewrite dynamic URL -

Discuss practical ways rearrange URLs using mod_rewrite.

myspace like - Mod rewrite dynamic URL -

Postby hp_solomon » Sun May 18, 2008 8:07 pm

I wish to have a myspace.com like profile URL for the site im working on, so users of the site will have URL like these

FOR USERPROFILES:
->http://www.site.com/username or http://site.com/username
will be redirected to or equivalent to :
->http://www.site.com/memberlist.php?mode=viewprofile&un=username

FOR USER CLANS:
->http://www.site.com/clan/clanname or http://site.com/clanname
will be redirected to or equivalent to :
->http://www.site.com/clan_page.php?cn=clanname

Any help will be greatly appreciated. Thanks in advance!
hp_solomon
 
Posts: 3
Joined: Sun May 18, 2008 7:58 pm

Postby hp_solomon » Sun May 18, 2008 8:08 pm

I tested the script i created it doesn't work. here is the complete script of .htaccess stored in the root directory of the site

Code: Select all
<Files "config.php">
Order Allow,Deny
Deny from All
</Files>

<Files "common.php">
Order Allow,Deny
Deny from All
</Files>

<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ /memberlist.php?mode=viewprofile&un=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^clan/([^/]+)/?$ /clan_page.php?cn==$1 [L]
</IfModule>


I got this error when accessing a url like site.com/username

Not Found

The requested URL /username was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
hp_solomon
 
Posts: 3
Joined: Sun May 18, 2008 7:58 pm

Postby david64 » Mon May 19, 2008 4:02 am

http://www.site.com/memberlist.php?mode ... n=username

Try:

Code: Select all
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)?$ memberlist.php?mode=$1&un=$2
david64
 
Posts: 15
Joined: Wed Mar 26, 2008 2:16 pm

Postby hp_solomon » Mon May 19, 2008 4:13 am

Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine on
Options +Followsymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)?$ /memberlist.php?mode=$1&un=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^clan/([^/]+)/?$ /clan_page.php?cn=$1 [L]
</IfModule>


tried this one and still got error 404 on viewing user profiles with this URL http://site.com/username

:(
hp_solomon
 
Posts: 3
Joined: Sun May 18, 2008 7:58 pm

Postby richardk » Mon May 19, 2008 10:28 am

What characters are allowed in the username?

Try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^clan/([^/]+)/?$ /clan_page.php?cn=$1 [QSA,L]

  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule ^([^/]+)/?$ /memberlist.php?mode=viewprofile&un=$1 [QSA,L]
</IfModule>
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 28 guests

cron