Welcome to WebmasterWorld Guest from 54.146.248.111

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

myspace like - Mod rewrite dynamic URL -

myspace like - Mod rewrite dynamic URL -

     

hp_solomon

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

5+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

5+ Year Member




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

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

5+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

5+ Year Member



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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

5+ Year Member



like how?

jdMorgan

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

5+ Year Member



thank you for the clarification. got it working now.

thanks for the advice...

 

Featured Threads

Hot Threads This Week

Hot Threads This Month