htaccess重写不带.php扩展名的URL到文件 [英] htaccess Rewrite URL Without .php Extension To File

查看:66
本文介绍了htaccess重写不带.php扩展名的URL到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got a website that using osCommerce which all the page can be access directly with http://www.example.com/pagename.php, but now I would like to tweak the htaccess file so that it can supports http://www.example.com/username and then redirecting to http://www.example.com/account.php?id=username, while other pages still can be access using the same old way.

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

It means that if the htaccess detect that the URL didn't have any extension, then it will be redirecting to http://www.example.com/account.php?id=username.

谢谢!

推荐答案

您只需要一个规则:

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

这篇关于htaccess重写不带.php扩展名的URL到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆