我想我可以使用.htaccess文件对于这一点,但我看着它,并没有发现任何有用的。我想要做的是有我的网站重定向到PHP页面,当用户键入其URL中的用户名,如:
I think I can use the .htaccess file for this, but I've looked it up and not found anything useful. What I want to do is have my site redirect to a php page when a user types their username in the URL like:
example.com/username
和拥有它是一样的PHP页面,如:
And have it be the same as a PHP page like:
example.com/name.php?id=username
我想它显示为 example.com/username
重定向即使经过,但它是没有必要的。任何想法?
I'd like it to display as example.com/username
even after it redirects, but it is not necessary. Any ideas?
您可以使用的 的mod_rewrite
透明地改写服务器上的网址。
You can use mod_rewrite
to transparently rewrite your URLs on the server.
假设你只拥有用户名以下的领域,这样的事情会做你想要的:
Assuming that you'd only have usernames following your domain, something like this would do what you want:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ name.php?id=$0