Mod rewrite 将工作URI重写为新格式

Mod rewrite 将工作URI重写为新格式,mod-rewrite,Mod Rewrite,我正在使用此设置网站URL重定向的格式。我在正确重定向时遇到问题 浏览器链接如下所示: http://www.exampledomain.com/1234/user http://www.exampledomain.com/index.php?id=1234&username=user 我的项目需要这样: http://www.exampledomain.com/1234/user http://www.exampledomain.com/index.php?id=1234&

我正在使用此设置网站URL重定向的格式。我在正确重定向时遇到问题

浏览器链接如下所示:

http://www.exampledomain.com/1234/user
http://www.exampledomain.com/index.php?id=1234&username=user
我的项目需要这样:

http://www.exampledomain.com/1234/user
http://www.exampledomain.com/index.php?id=1234&username=user
但我不知道怎么做

RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index.php?id=$1
试试这个

RewriteEngine on
RewriteBase /

RewriteRule ^/?([-a-zA-Z0-9_+]+)/?([-a-zA-Z0-9_+]+)/?$ /index.php?id=$1&username=$2
对不起:

不带/before index.php的新更正

RewriteRule ^/?([-a-zA-Z0-9_+]+)/?([-a-zA-Z0-9_+]+)/?$ index.php?id=$1&username=$2 [L]
如果您的基本url是www.domanin.com/folder1/folder2,那么此行将是:

RewriteBase /folder1/folder2

我在.htaccess中添加了您的代码,并重新启动了我的httpd,但当我请求url/1234/user时,却找不到404。我应该做任何其他的工作吗?你的基本url是什么?很抱歉你尝试了这个。RewriteRule^/?[-a-zA-Z0-9_+]+/?[-a-zA-Z0-9_+]+/?$index.php?id=$1和username=$2第一个答案很好,我只需在最后一行加上[L],非常感谢