简体   繁体   中英

How to modify htaccess url rewrite just how facebook does

I want to automatically gather up a respective path name to the users input so for example with facebook.

A user creates a page/user profile with the name JohnDoe777 thus their url is: facebook.com/JohnDoe777.

How can one do that? I know it deals with the .htaccess file but I need careful instructions on how to do it so in case I don't mess anything up on my local server.

It is what we call URL rewriting.

You can find a good example here

http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

This has nothing to do with rewrite, although it may be done with rewrite rules.

In FaceBook, and a ton of other sites, you can access information just by what is typed on the URL by parsing that information on a PHP/ASP/JSP/perl/etc file. The idea is that when some data is stored, a unique URL is assigned to that set of data. Then the data can be accessed by using that URL.

This pseudocode helps to get the idea

data = false;

requested_url = 'http://www.example.com/JohnDoe777';

data_to_retrieve = JohnDoe777

check_if_data_in_database = query_the_database_for( 'JohnDoe777' );

if ( check_if_data_in_database === false ) {
    check_if_data_in_file = look_for_file( 'JohnDoe777' );
}

if ( data !== false ) {
    process_and_present_data( 'JohnDoe777' );
}

if ( data === false ) {
    tell_user_an_error_happened_or_no_data_available
}

Of course you can do a rewrite for something like

example.com/JohnDoe777

to

example.com/index.php?user=JohnDoe777

But both methods work for gathering/presenting data that has been created and stored and the rewrite step is just an extra, common, but not necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM