如何将短url重定向到带有参数的php文件

如何将短url重定向到带有参数的php文件,php,url-rewriting,rewrite,Php,Url Rewriting,Rewrite,您好,以下是我要做的: 如果有人访问site.com/myusername,他们会被发送到site.com/index.php?a=profile&u=myusername 如果您了解htaccess重写引擎,应该非常简单。还有类似的初学者教程吗 这是我的礼物。htaccess: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{reque

您好,以下是我要做的: 如果有人访问site.com/myusername,他们会被发送到site.com/index.php?a=profile&u=myusername

如果您了解htaccess重写引擎,应该非常简单。还有类似的初学者教程吗

这是我的礼物。htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{request_filename} -f [OR]
RewriteCond %{request_filename} -d
RewriteRule ^ - [L]

RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ /index.php?a=$1&q=$3 [L,QSA]

RewriteRule ^(.+?)/?$ /index.php?a=profile&u=$1 [L,QSA]

通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放入
文档根目录下的
.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php?a=profile&u=$1 [L,QSA]

如果url是指定的,则可以执行以下操作

if (!isset($_REQUEST['u'])) {

$x = $_SERVER['REQUEST_URI'];
$y = str_replace('?', '', $x);
$z = str_replace('/', '', $y);
header("Location: ?a=profile&u=$z"); }

虽然不是一个很好的解决方案,但这正是我所能想到的……如果你想用php来做……我知道你已经得到了答案。但我在一小时前就想好了。但是我的系统出了问题,所以只有我以后才会发布。 这也是一种方法

Options +FollowSymlinks
RewriteEngine On
RewriteBase /  
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ /index.php?a=profile&q=$1

你应该尝试搜索现有的帖子。在这里和其他地方加载关于如何重写URL的其他帖子。试着学习使用搜索工具,你们会发现开发非常容易谢谢你们,我正在检查那些链接Shello anubhava。已经有一个:RewriteCond%{request_filename}-f RewriteRule^(.*)$1[L]RewriteRule^([^/]*)+)(/([^/]{0,32})(/.+)?)?$index.php?正在使用的顶部a=$1&q=$3[L]。你能编辑代码吗?因为当我在下面加上你的时,它不像你那样工作。如果您仍然面临问题,请在您的问题中提供您当前的.htaccess(而不是评论)。请检查。我添加了itI。我在您的问题中编辑了您的.htaccess,并建议进行更改。