想知道是否有人可以帮助我为我的网站编写一些重写规则。
看看下面的 URL,看看我需要如何重写它们。
http://www.example.com/essays-and-reports/
does not need to be re-written, it is a physical folder on the web server.
http://www.example.com/essays-and-reports/business/
needs to rewrite to (root)/first_level_template.php
http://www.example.com/essays-and-reports/dynamic_name2
needs to rewrite to (root)/first_level_template.php
http://www.example.com/essays-and-reports/business/financial-reports/
needs to rewrite to (root)/second_level_template.php
http://www.example.com/essays-and-reports/blah/financial-reports/C_B_2413_Report_on_savings.php
needs to rewrite to (root)/final_level_template.php
请注意,无论尾部斜杠如何,规则都必须有效。 总而言之,我需要将三个级别重写到其相关模板中。以上都不存在在服务器上,包括最终级别的PHP文件。唯一存在的是论文和报告文件夹,它是网站的主文件夹。
我尝试了这样的事情,但我在日志中出现编译错误。
RewriteRule ^([^/]+)/([^/]+)/?$ /second-level-template.php [L]
如果你能帮我写我需要的规则 - 我非常感谢。
编辑:这段代码有点有效,但它也重写了我不想要的论文和报告文件夹......
Options +FollowSymLinks
RewriteEngine On
RewriteBase /essays-and-dissertations/
RewriteRule ^[^/]+/[^/]+/[^/]+/?$ /final_level_template.php [L]
RewriteRule ^[^/]+/[^/]+/?$ /second_level_template.php [L]
RewriteRule ^[^/]+/?$ /first_level_template.php [L]
您可以使用 3 条规则来执行此操作:
RewriteRule ^essays-and-reports/[^/]+/?$ /first_level_template.php [L]
RewriteRule ^essays-and-reports/[^/]+/[^/]+/?$ /second_level_template.php [L]
RewriteRule ^essays-and-reports/[^/]+/[^/]+/[^/]+/?$ /final_level_template.php [L]
您不需要转义重定向目标中的点,因为这不是正则表达式。