Php,重定向非扩展到索引+重定向用户名到用户页面


php, redirect non extension to index + redirect usernames to user page

我在google和stackoverflow上搜索了很多,但没有找到完整的答案…

我想做的是:

1)将所有非扩展地址重定向到它们的页面。例如:home -> home.php

2)将用户名重定向到搜索用户名的页面,如果存在,则加载另一个页面。例如:www.example.com/michael将重定向到go.php并获取"michael",如果user存在;转到user。php?id =迈克尔

完全像facebook和twitter!如果你输入"家",它会去主页,如果你输入你的用户名,它会去你的个人资料!

我怎么能做这样的事?


EDIT:或者可能是一个.htaccess,它将第一个斜杠之后的任何内容发送到页面。例如:

www.example.com/this/is/test
将:

www.example.com/index.php?var1=this&var2=is&var3=test

然后index.php页面会决定做什么

你可以试试:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)?/?([^/]+)?/?([^/]+)?/?   [NC]
RewriteRule .*     index.php?var1=%1&var2=%2&var3=%3   [L]

地图默默地

http://www.example.com/this/is/test

http://www.example.com/index.php?var1=this&var2=is&var3=test

所有参数可选,最多3个

如果需要更多,请在

右端每增加一个([^/]+)?/?

RewriteCond %{REQUEST_URI}

行,并添加键(varN)对应于rewriterrule中的index.php查询,使用%N反向引用它们。