PHP和htaccess的重定向:重写yoursite.com/user.php?username=xyz到yoursite.com/xyz~~V [英] PHP and htaccess redirection: Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
问题描述
让我们说,我想用的.htaccess重写以下。
let's say I want to use .htaccess to rewrite the following.
重写 /user.php?username=xyz
到 / XYZ
。
我会用:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
现在的问题是,一旦这样做了,我怎么访问的用户名在我的其他环节?
The problem is once this is done, how do I access the username in my other links?
让 /mike/details.php
如何获得用户名('迈克')的值会自动被添加到URL,以便它是这样的:
/username/details.php?username=mike
How do I get the value of username ('mike') to automatically be added to the URL so it's like:
/username/details.php?username=mike
什么,我需要在.htaccess更改为得到这个值?或者,我必须这样做,在PHP脚本解析网址是什么?
What would I need to change in .htaccess to get this value? Or do I have to do it in the PHP script to parse the URL?
感谢
推荐答案
这将与其他规则重叠的站点开始与anytext
喜欢说 ^ ABC
This will overlap with other rules in the site with starts with anytext
like say ^abc
这篇关于PHP和htaccess的重定向:重写yoursite.com/user.php?username=xyz到yoursite.com/xyz~~V的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!