谢谢大家的耐心和帮助。我完全重申了这个问题,因为我的所有修改都会变得很长。 我有4个的入口点的PHP MVC框架:URL重写帮助
从根:
的index.php
索引ajax.php
管理员/ index.php的
管理员/索引-ajax.php
我需要一个.htcaccess文件,它可以接受任何请求,并根据url将其重写到相应的文件中。长的网址是index.php?rt = cms/view/15,我希望它是index/cms/view/15。除了一个问题外,这一部分已经完成了。
这是我现在的.htaccess文件:
# htaccess file for framework - GOOD
Options +FollowSymLinks
# Turn on the mod_rewrite engine - GOOD
RewriteEngine On
# Hide indexes - GOOD
Options -Indexes
# If a file is not one of these, continue processing. - GOOD
RewriteRule \.(css|js|jpg|jpeg|png|gif|ico)$ - [L]
# RewriteRules for folder index files
#RewriteRule ^(index)?(.php)?$ index.php [L] - GOOD
#RewriteRule ^admin(/?)(index)?(.php)?$ admin/index.php [L] - GOOD
# RewriteRules for admin folder arguements - going from more specific to less
RewriteRule ^admin/ajax/[A-Za-z0-9-_/]*$ admin/index-ajax.php?rt=$1 [L]
RewriteRule ^admin/[A-Za-z0-9-_/]*$ admin/index.php?rt=$1 [L]
# RewriteRule for root ajax file
RewriteRule ^ajax/[A-Za-z0-9-_/]*$ index-ajax.php?rt=$1 [L]
# RewriteRule for root file - by here, it is not ajax or admin related, so only
# possible option left if the root index file
RewriteRule ^[A-Za-z0-9-_/]*$ index.php?rt=$1 [L]
我做了一个简单的网站有两个文件夹 - “根”和“根/管理员”,而且每个的内部的CSS,图片,和一些虚拟内容的JavaScript文件夹。在'root'和'root/admin'里面有一个index.php和index-ajax.php文件,可以简单地输出任何url参数,并且使用来自每个文件夹的css,js和image文件。
我现在的问题是,如果我做一个像索引/等等或/管理/索引/等等的网址,那么该网页提出正确的参数是正确的。然而,当我做了像索引/等/视图或管理/索引/等/视图的网址然后争论是正确的(?rt = blah /视图),但页面呈现错误,因为css/js/images文件去索引/ blah/[css]而不是索引/ [css]。
有关如何处理此问题的任何想法?我允许css/js/image文件通过.htaccess原样通过,因此在那里的工作量会减少。
我只是不明显键入速度不够明显。 – seth 2009-07-08 21:50:22
我认为$符号可作为占位符将来自左侧网址的值转移到正确的网址中? – 2009-07-08 21:52:34
他意味着第一部分中的$,/ – seth 2009-07-08 21:53:36