Ask a question about apache rewrite
PHPz
PHPz 2017-05-16 17:04:19
0
3
745

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]
PHPz
PHPz

学习是最好的投资!

reply all(3)
巴扎黑

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.

漂亮男人

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

巴扎黑

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template