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=login2)我想用我的.htaccess设置一些网址重定向,这样如果有人浏览某个路径,就会自动重定向到/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)有什么线索吗?非常感谢!
发布于 2011-06-15 21:55:03
对于1)你可能会颠倒你的问题,mod-rewrite的工作是读取脏index.php并找到真正的文件,所以你想要的是使用一个错误的url (没有index.php),mod-rewrite会找到这个url。PHP Mod-rewrite不会修改你的,它是你的应用程序代码作业(PHP?)。
因此,假设您的应用程序正在编写以下url:
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):嗯,这还不清楚。您总是希望重定向试图访问您的类目录的用户吗?然后是两件事:
Redirect和RedirectMatch关键字的模块,所以你可以这样写:类永久/ RedirectMatch /.* http://www.example.com/
像往常一样,检查this page:中可以轻松完成的规则,而无需进入mod-rewrite的大脑循环。
https://stackoverflow.com/questions/6347018
复制相似问题