在.htaccess重写中遗漏了一些明显的东西

时间:2012-12-18 18:18:02

标签: .htaccess mod-rewrite

我的目标很简单:

  1. 任何与/special一起讨论的内容都应转到/SpecialHandler.php
  2. 其他一切都应该转到/index.php
  3. 我的基本配置是这样编写的,但它不起作用:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^/special(.*)/?$ SpecialHandler.php [L,NC]
    RewriteRule ^.*/?$ index.php [L]
    

    以下是发生的事情:

    • localhost - 工作正常
    • localhost / bla_bla-bla%20bla - 工作正常
    • localhost / special / - 转到index.php而不是SpecialHandler.php
    • localhost / special / fu / bar / bat - 转到index.php而不是SpecialHandler.php

    这一点显而易见,我错过了。

1 个答案:

答案 0 :(得分:1)

删除第一个/特殊规则:

RewriteRule ^special(.*)/?$ SpecialHandler.php [L,NC]

它应该有用

- 完成工作htaccess

RewriteEngine on
RewriteBase /a/
RewriteRule ^special(.*)/? SpecialHandler.php [NC,L]
RewriteRule ^.*/?$ index.php [L]

url:

http://localhost/a/special => special
http://localhost/a/special/really => special
http://localhost/a/index.php => index
http://localhost/a/foobarbaz => index
相关问题