htaccess重写没有.php扩展名到文件的URL

Pin*_*ing 2 php apache .htaccess mod-rewrite url-rewriting

我有一个使用osCommerce的网站,所有页面都可以直接访问http://www.example.com/pagename.php,但现在我想调整htaccess文件,以便它可以支持http://www.example.com/username然后重定向到http://www.example.com/account.php?id=username,而其他页面仍然可以使用相同的旧方式访问.

这意味着如果htaccess检测到URL没有任何扩展名,那么它将重定向到http://www.example.com/account.php?id=username.

谢谢!

anu*_*ava 6

你只需要一条规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ /account.php?id=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)