PHP和htaccess的重定向:重写yoursite.com/user.php?username=xyz到yoursite.com/xyz~~V重写、重定向、yoursite、htaccess

2023-09-02 00:30:30 作者:为爱战天下

让我们说,我想用的.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