www.domain.com/4 Short URL question

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

www.domain.com/4 Short URL question

Postby mrblack » Mon Apr 30, 2007 5:15 pm

I want to have redirection look like this
http://www.domain.com/4 instead of http://domain.com/member4.html

Like myspace does with member id's

Later of course I want to create a new field that is filled out it will replace the userid with the field data. But I am sure that is a difficult task so that is on hold for awhile. lol
mrblack
 
Posts: 8
Joined: Thu Apr 26, 2007 12:59 pm

Advertisement

Postby dcz » Tue May 01, 2007 9:31 am

Actually, thanks to the zero dupe, it's really easy.

You'd only need to add a rewriterule to handle these.

Just add :

Code: Select all
# shorter PROFILES
RewriteRule ^([0-9]+)$ /profile.php?mode=viewprofile&u=$1 [QSA,L,NC]


After :

Code: Select all
#PROFILES
RewriteRule ^membre([0-9]+)\.html$ /profile.php?mode=viewprofile&u=$1 [QSA,L,NC]


in your .htaccess (could need to add paths like in your other rewriterules).

The zero dupe will do the rest ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby mrblack » Tue May 01, 2007 3:21 pm

thanks that worked :) you are a life saver. How hard would it be to create redirecting from http://www.domain.com/customurl and custom url being a costom field I added via registration?
mrblack
 
Posts: 8
Joined: Thu Apr 26, 2007 12:59 pm

Postby dcz » Tue May 01, 2007 3:29 pm

Well, it all depends on what would be the variables content and how you'd catch it by the script.

If the variable only contains a text strig without spaces, you could go for something like :

Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9]+)$ /script.php?var=$1 [QSA,L,NC]


We need the rewritecond here to first make sure a physical file with the same name as the text string sent does not really exist, in such case, we give it the priority to let it load.

If you where using a folder with only script.php in it, you could have the reg-ex working faster with only :
Code: Select all
RewriteRule ^folder/([a-z0-9]+)$ /folder/script.php?var=$1 [QSA,L,NC]


But this is only a possible example, what would you put into this added field, and what would you like to do with it ?

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby mrblack » Tue May 01, 2007 4:28 pm

custom field would be restricted of special characters/spaces and limited to 20 characters. I know how to add a custom field to profile/registration cause I read the tutorial lol. Example.

Custom URL: http://www.scenespot.com/ [text input]
Once chosen your custom url cannot be changed.

http://www.phpbb.com/community/viewtopi ... &sk=t&sd=a
is the url for the tutorial I used to add a new field. So that part I understand and have used this for other things to display data in the profile. but once I have created it lets call it 'customurl' then how do I get that to redirect using that data?
mrblack
 
Posts: 8
Joined: Thu Apr 26, 2007 12:59 pm

Postby dcz » Wed May 02, 2007 8:18 am

So this is the input, what would be the php script targeted ?

Here you seems to be in the case where the rewriterule I suggested will work, as long as you update the targeted script.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby mrblack » Wed May 02, 2007 4:15 pm

the input will be stored in database and hopefull take you to the profile jusy as http://www.scenespot.com/4 would
mrblack
 
Posts: 8
Joined: Thu Apr 26, 2007 12:59 pm

Postby dcz » Wed May 02, 2007 4:52 pm

Then, assuming you'll be using a new GET var for this one, and deal with it in the php script to link it to the user id, this should do it, preferably at the end of your .htaccess to avoid possible confusion with other rules :
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9]+)$ /profile.php?mode=viewprofile&stringvar=$1 [QSA,L,NC]


You should, with this, use $_GET['stringvar'] in profile.php to catch this var.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm


Return to Apache mod Rewrite

Who is online

Users browsing this forum: No registered users and 2 guests