简体   繁体   English

如何修改htaccess的URL重写Facebook如何

[英]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. 我想自动收集用户输入的相应路径名,例如使用facebook。

A user creates a page/user profile with the name JohnDoe777 thus their url is: facebook.com/JohnDoe777. 用户创建名为JohnDoe777的页面/用户个人资料,因此其网址为: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. 我知道它处理.htaccess文件,但是我需要谨慎的操作方法,以防万一我在自己的本地服务器上没有任何混乱。

It is what we call URL rewriting. 这就是我们所说的URL重写。

You can find a good example here 你可以在这里找到一个很好的例子

http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/ 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. 在FaceBook和许多其他站点中,您可以通过在PHP / ASP / JSP / perl / etc文件中解析该信息来仅通过URL中键入的内容来访问信息。 The idea is that when some data is stored, a unique URL is assigned to that set of data. 想法是,当存储某些数据时,会将唯一的URL分配给该组数据。 Then the data can be accessed by using that URL. 然后可以使用该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. 但是,这两种方法都可以用于收集/呈现已创建和存储的数据,并且重写步骤只是额外的,普通的,但不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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