Url Rewrite - 添加查询字符串Too 999

时间:2016-01-03 19:29:49

标签: .htaccess

DirectoryIndex index.php
    <IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /
    RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
    RewriteRule . %1/%2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
    RewriteRule ^tags tags.php [L,NC]

    </IfModule>

我想添加新页面。但是找不到写页面。为什么?请帮帮我。

RewriteRule ^ tags tags.php [L,NC] //我想要这个www.example.com/tags打开tags.php?

1 个答案:

答案 0 :(得分:0)

您需要重新排序htaccess规则,如下所示:

DirectoryIndex index.php
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
    RewriteRule . %1/%2 [R=301,L]
    RewriteRule ^tags/?$ tags.php [L,NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]


    </IfModule>

问题是,你的规则

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]

将任何请求(不是真正的文件/目录)重写为index.php。因为/ tags不是您目录中的现有文件,所以http://example.com/tags的请求被重写为/index.php,并且最后一条规则从未执行过。