homepage Welcome to WebmasterWorld Guest from 54.196.198.213
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
myspace like - Mod rewrite dynamic URL -
myspace like - Mod rewrite dynamic URL -
hp_solomon




msg:3650884
 2:42 pm on May 15, 2008 (gmt 0)

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 [site.com...]
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 [site.com...]
will be redirected to or equivalent to :
->http://rakista.com/clan_page.php?cn=clanname

Any help will be greatly appreciated. Thanks in advance!

 

jdMorgan




msg:3651271
 8:54 pm on May 15, 2008 (gmt 0)

See if this helps: Changing dynamic to static URLs [webmasterworld.com] Search engine-friendly links with mod_rewrite

Then post your best-effort code for discussion [webmasterworld.com].

Jim

hp_solomon




msg:3652383
 4:20 am on May 17, 2008 (gmt 0)


Thanks for the reply.

Based on my readings, i comeup with this script?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ /memberlist.php?mode=viewprofile&un=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^clan/([^/]+)/?$ /clan_page.php?cn==$1 [L]

I'm also thinking if "Options +Followsymlinks" is required to add in the script. Any thoughts?

Thanks

hp_solomon




msg:3652384
 4:47 am on May 17, 2008 (gmt 0)

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

<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 /ridz was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

jdMorgan




msg:3652580
 3:28 pm on May 17, 2008 (gmt 0)

You example URL did not contain a leading "clan/" or a trailing slash. Therefore, it did not match either rule, so you got a 404.

You may wish to make the trailing slash optional in the first rule pattern, as you did in the second.

Somewhere (perhaps using cPanel) you have declared a custom 404 error document, but that document does not exist. You should create a custom 404 error page, somewhat apologetic in tone, explaining that the requested URL is missing for unknown reasons, and provide links to your home page, your site map, a product category selector, and your site search facility, as appropriate.

It is also sometimes useful to include a meta-refresh on that error page, leaving more than enough time for the visitor to read the entire page and select a link, and then refresh to whichever of the above-listed pages you feel is most appropriate. Do NOT use a short-period meta-refresh, or you will have trouble with search engines treating it as a redirect.

You can override the previous error document declaration (from cPanel?) in your .htaccess file if you wish, using a directive of the form:

ErrorDocument 404 /local-path-to-your-custom-404-error-page.html

Note that the path is a local filepath, not a URL. Again, if you get that wrong, you'll have major trouble with search engines. This is because, as documented, ErrorDocument will generate a 302 redirect if a full URL is specified, and therefore, search engines will *never* see a 404 from your server. This causes many problems with indexed URLs and reduced depth of crawling, because the search engines cannot tell what URLs are 'good' and what URLs are 'bad' on your site -- None return a 404, and all either provide content directly, or redirect to content. This common mistake has a huge negative impact on many sites.

Jim

hp_solomon




msg:3652595
 3:46 pm on May 17, 2008 (gmt 0)

hmmm...

i'm testing it first on the user profiles URLs.. www.site.com/username or site.com/username and it still doesnt work..

add slash before clan like this?

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]

g1smd




msg:3653261
 10:44 pm on May 18, 2008 (gmt 0)

You requested site.com/username in your test.

You would have needed to request site.com/username/ for your rule to have matched and worked.

hp_solomon




msg:3653502
 10:44 am on May 19, 2008 (gmt 0)

like how?

jdMorgan




msg:3653696
 3:33 pm on May 19, 2008 (gmt 0)

If you type in "site.com/username" then neither rule will apply, because the first rule requires a trailing slash on the URL, as in "site.com/username/", and the second rule requires that the URL you type in start with "/clan". As I suggested in my post above, you can make the trailing slash optional in the first rule pattern, just as you did in the second rule. Please review the posts above if this is not clear -- Otherwise, your respondents' time is wasted.

If you have questions about regular expressions, please review the regular expressions tutorial cited in our forum charter.

Jim

g1smd




msg:3653845
 6:48 pm on May 19, 2008 (gmt 0)

The code you posted requires a trailing slash. That is the way that you have coded it.

In the test that you said you did, you didn't have a trailing slash on what you typed into the browser.

hp_solomon




msg:3653992
 9:08 pm on May 19, 2008 (gmt 0)

thank you for the clarification. got it working now.

thanks for the advice...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved