<i id='GbyOq'><tr id='GbyOq'><dt id='GbyOq'><q id='GbyOq'><span id='GbyOq'><b id='GbyOq'><form id='GbyOq'><ins id='GbyOq'></ins><ul id='GbyOq'></ul><sub id='GbyOq'></sub></form><legend id='GbyOq'></legend><bdo id='GbyOq'><pre id='GbyOq'><center id='GbyOq'></center></pre></bdo></b><th id='GbyOq'></th></span></q></dt></tr></i><div id='GbyOq'><tfoot id='GbyOq'></tfoot><dl id='GbyOq'><fieldset id='GbyOq'></fieldset></dl></div>
        <bdo id='GbyOq'></bdo><ul id='GbyOq'></ul>

      <small id='GbyOq'></small><noframes id='GbyOq'>

      1. <tfoot id='GbyOq'></tfoot>
        <legend id='GbyOq'><style id='GbyOq'><dir id='GbyOq'><q id='GbyOq'></q></dir></style></legend>
      2. RewriteRule htaccess 总是删除尾部斜杠偶数目录

        RewriteRule htaccess to always remove trailing slash even directory(RewriteRule htaccess 总是删除尾部斜杠偶数目录)
        <tfoot id='IE53r'></tfoot>

      3. <i id='IE53r'><tr id='IE53r'><dt id='IE53r'><q id='IE53r'><span id='IE53r'><b id='IE53r'><form id='IE53r'><ins id='IE53r'></ins><ul id='IE53r'></ul><sub id='IE53r'></sub></form><legend id='IE53r'></legend><bdo id='IE53r'><pre id='IE53r'><center id='IE53r'></center></pre></bdo></b><th id='IE53r'></th></span></q></dt></tr></i><div id='IE53r'><tfoot id='IE53r'></tfoot><dl id='IE53r'><fieldset id='IE53r'></fieldset></dl></div>

        <small id='IE53r'></small><noframes id='IE53r'>

            • <bdo id='IE53r'></bdo><ul id='IE53r'></ul>
                <tbody id='IE53r'></tbody>

                <legend id='IE53r'><style id='IE53r'><dir id='IE53r'><q id='IE53r'></q></dir></style></legend>

                • 本文介绍了RewriteRule htaccess 总是删除尾部斜杠偶数目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  目标是结合几个规则:

                  • 在 URI 中永远不要有斜杠
                  • 在调用 domain.tld/somedir 时内部重写为 index.php (domain.tld/somedir/index.php)
                  • 删除文件扩展名,检查 + '.php' 是否存在并最终在内部对其进行重写
                  • never have a trailing slash in the URI
                  • internally rewrite to the index.php (domain.tld/somedir/index.php) when calling domain.tld/somedir
                  • remove file extensions, check if + '.php' exists and eventually internally rewrite to it

                  这将在.htaccess"中完成,因为这是我唯一可访问的.

                  This is to be done in '.htaccess' as this is my only accessible .

                  我目前的尝试

                  # check if *.php exists
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{REQUEST_FILENAME}.php -f
                  RewriteRule ^(.*[^/])/?$ $1.php [L, QSA]
                  
                  # do not allow trailing slash
                  RewriteRule (.*)/ $1 [L, R=301]
                  

                  这里的难点在于查询domain.tld/somedir"在被重定向到domain.tld/somedir/"后通常会调用目录的index.php.但是,我希望在查询domain.tld/somedir"时在内部调用 index.php(没有 301)直接.

                  The difficulty here is that the query 'domain.tld/somedir' normally calls the directory's index.php after having been redirected to 'domain.tld/somedir/'. However, I would like the index.php to be internally called (no 301) directly when querying 'domain.tld/somedir'.

                  推荐答案

                  您可以使用以下代码:

                  DirectoryIndex index.php
                  RewriteEngine On
                  
                  # remove trailing slash
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{THE_REQUEST} s(.+?)/+[?s]
                  RewriteRule ^(.+?)/$ /$1 [R=301,L]
                  
                  # To internally forward /dir/file to /dir/file.php
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
                  RewriteRule ^(.+?)/?$ /$1.php [L]
                  

                  这篇关于RewriteRule htaccess 总是删除尾部斜杠偶数目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)
                      <tbody id='pN7Qq'></tbody>
                  • <small id='pN7Qq'></small><noframes id='pN7Qq'>

                      <tfoot id='pN7Qq'></tfoot>
                        <bdo id='pN7Qq'></bdo><ul id='pN7Qq'></ul>
                          <legend id='pN7Qq'><style id='pN7Qq'><dir id='pN7Qq'><q id='pN7Qq'></q></dir></style></legend>

                        • <i id='pN7Qq'><tr id='pN7Qq'><dt id='pN7Qq'><q id='pN7Qq'><span id='pN7Qq'><b id='pN7Qq'><form id='pN7Qq'><ins id='pN7Qq'></ins><ul id='pN7Qq'></ul><sub id='pN7Qq'></sub></form><legend id='pN7Qq'></legend><bdo id='pN7Qq'><pre id='pN7Qq'><center id='pN7Qq'></center></pre></bdo></b><th id='pN7Qq'></th></span></q></dt></tr></i><div id='pN7Qq'><tfoot id='pN7Qq'></tfoot><dl id='pN7Qq'><fieldset id='pN7Qq'></fieldset></dl></div>