【发布时间】:2012-05-13 10:41:24
【问题描述】:
请帮助我为 mod_rewrite 创建正确的说明。这似乎很难。
我需要以下内容:
1。 重定向从 www.site.com 到 site.com。
www.site.com/hello ==> site.com/hello
www.site.com/abc/def ==> site.com/abc/def
等等,然后应该应用其他规则。
2。直接访问(不重写)某些指定文件和文件夹(如robots.txt、images/等)
也许
RewriteCond %{REQUEST_URI} !^/(robots.txt|favicon.ico|images|documents|~.\*)
我说的对吗? 所以,像
这样的网址site.com/robots.txt ==> site.com/robots.txt
site.com/documents/file1.pdf ==> site.com/documents/file1.pdf
应保持原样,不应重写。
3。另一个转变:
site.com/index.php?anythinghere ==> site.com/a/index.php?anythinghere
4。但是如果我们输入 URLs site.com 和 site.com/ Apache 应该调用根文件夹中的 index.php (site.com/index.php)
site.com ==> site.com/index.php
site.com/ ==> site.com/index.php
5。我有 MVC 脚本,如果我们键入以下 URL:
1. site.com/controller or site.com/controller/ or site.com/controller//
2. site.com/controller/function or site.com/controller/function/
3. site.com/controller/function/parameter or site.com/controller/function/param1/param2/param3
并且如果控制器是列表中预定义的单词之一,例如“index”、“news”、“contacts”(可能会扩展到数百个单词),那么我们应该调用 index.php,按照以下方式重写 URL:
site.com/controller ==> site.com/index.php?q=controller
site.com/controller/ ==> site.com/index.php?q=controller/
site.com/controller// ==> site.com/index.php?q=controller//
site.com/controller/function ==> site.com/index.php?q=controller/function
site.com/controller/function/ ==> site.com/index.php?q=controller/function/
site.com/controller/function/parameter ==> site.com/index.php?q=controller/function/parameter
site.com/controller/function/param1/param2/param3 ==> site.com/index.php?q=controller/function/param1/param2/param3
6。最后,如果没有应用所有之前的规则,我们应该重写
site.com/anythinghere ==> site.com/a/index.php?anythinghere
希望apache不要递归使用mod_rewrite,否则不同的index.php会有很大的麻烦。
我知道这并不容易,但如果您能帮助为一件物品创建规则,那就太好了。
提前致谢!
【问题讨论】:
-
我对您的问题进行了一些编辑,以便更清楚地进行转换。希望对您有所帮助。
标签: apache mod-rewrite