search

Home  >  Q&A  >  body text

Ask a question about apache rewrite

I don’t know why there is a slash missing after rewriting

The following is the go.php code

<?php
$url=$_GET['url'];
$url=urldecode($url);
echo $url;
?>

rewrite rules are as follows

RewriteEngine On
RewriteRule ^go/(.*)$ go.php?url= [QSA]
PHPzPHPz2754 days ago747

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 17:06:19

    Reference Why is Apache removing multiple slashes?
    @Pekka 웃 pointed out that multiple adjacent /不符合RFC标准,@Pekka 웃 猜测Apache被设计为将多个相邻的/ in the URI are merged into one.


    Similarly, after searching, I learned that there is a configuration such as merge_slashes in nginx, which is used to enable or disable the function of merging two or more adjacent slashes in the request URI into one . The default configuration is Turn on . It can be seen that apache and nginx have consistent behavior when handling multiple adjacent / in URI by default, and both follow the RFC standard.


    As for the // in http://localhost/go.php?url=http://www.163.com/, they are not merged into one, but The // in http://localhost/go/http://www.163.com/ are merged into one. It should be that the former complies with the RFC standard, while the latter does not.

    I don’t have a deep understanding of the RFC standard, so the above statement may not be rigorous enough. If there are any mistakes, please point them out. But after understanding this level, I feel that it is almost enough. As for how to change the rewrite rules or code, please google it yourself.

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 17:06:19

    http://php.net/manual/zh/function.urldecode.php

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 17:06:19

    I guess Apache removed the // 化简成一个 / in the path.

    reply
    0
  • Cancelreply