怎么做这个URL重写?

时间:2022-06-26 08:52:09

Basically, when a user types in http://www.domain.com/username I want it to go to http://www.domain.com/user?u=username. Username is the name of the user whose page I want to visit. How can I do this? Do I need to make a URL rewrite? Is there a better way to do this? On almost all websites that involve user pages, you can simply type in something like YouTube.com/channel and Facebook.com/username. I want to be able to do that on my site. I am using php for my user pages.

基本上,当用户输入http://www.domain.com/username时,我希望它转到http://www.domain.com/user?u=username。用户名是我要访问其页面的用户的名称。我怎样才能做到这一点?我需要重写URL吗?有一个更好的方法吗?在几乎所有涉及用户页面的网站上,您只需输入类似YouTube.com/channel和Facebook.com/username的内容即可。我希望能够在我的网站上做到这一点。我正在使用php作为我的用户页面。

1 个解决方案

#1


0  

What you would need is to have an hypertext access file (.htaccess). This file will allow you to use URL rewriting. Here is what you would need to put inside that file:

你需要的是拥有一个超文本访问文件(.htaccess)。此文件将允许您使用URL重写。以下是您需要放在该文件中的内容:

RewriteEngine On
RewriteRule ^([^/]*)$ /user?u=$1 [L]

#1


0  

What you would need is to have an hypertext access file (.htaccess). This file will allow you to use URL rewriting. Here is what you would need to put inside that file:

你需要的是拥有一个超文本访问文件(.htaccess)。此文件将允许您使用URL重写。以下是您需要放在该文件中的内容:

RewriteEngine On
RewriteRule ^([^/]*)$ /user?u=$1 [L]