HTACCESS重写和重定向问题

| 1)如果文件扩展名是PHP或(S)HTM(L),我想创建一个重写规则,以删除URL末尾的文件。例如:
This: http://www.example.com/index.php
Becomes: http://www.example.com/

This: http://www.example.com/index.php?action=login
Becomes: http://www.example.com/?action=login
2)我想用.htaccess设置一些URL重定向,这样,如果有人浏览某个路径,则会自动重定向到/index.php。例如:
This: http://www.example.com/classes/(index.php)
Redirected To: http://www.example.com/(index.php)

This: http://www.example.com/classes/class.php
Redirected To: http://www.example.com/(index.php)

This: http://www.example.com/classes/style.css
Redirected To: http://www.example.com/(index.php)
有什么线索吗? 非常感谢!     
已邀请:
        对于1),您可能会反转您的问题,mod-rewrite的工作是读取脏网址并找到真实文件,因此您想要的是使用错误的url(不带index.php),而mod-rewrite会找到索引.php。 Mod-rewrite不会修改您的网址,这是您的应用程序代码作业(PHP?)。 因此,假设您的应用程序正在编写以下网址:
http://www.example.com/
Apache将使用的事实
http://www.example.com/index.php
要么
http://www.example.com/index.htm
要么
http://www.example.com/index.html
响应不是由mod-rewrite处理,而仅由Apache配置指令处理
DirectoryIndex index.php,index.htm,index.phtml
对于http://www.example.com/?action=login,它也应该起作用。 对于2):嗯,还不清楚。您是否始终要重定向尝试访问您的班级目录的人员?然后两件事: 如果不应该通过网络访问此目录,请将其放在Web目录之外,则没人会看到它,并且如果它仅包含php类,则PHp可以包含不在Web目录中的文件。如果它包含css和js文件,则表示错误,在根目录中重定向它们肯定不会给它们一个js或css 您不需要mod-rewrite即可使simpel重定向mod_alis,这是您当然拥有的模块(99%的机会)可以使用
Redirect
RedirectMatch
关键字来编写: RedirectMatch永久/classes/。*http://www.example.com/ 一如往常,请检查此页面:无需输入mod-rewrite即可轻松完成的规则​​。     

要回复问题请先登录注册