Mod Rewrite:域名

时间:2016-10-11 10:43:58

标签: php apache .htaccess mod-rewrite url-rewriting

我试图创建一个重写规则,将带参数的URL更改为正斜杠后跟参数。

RewriteRule: RewriteRule ^(.*)$ send.php?url=$1&name=&submit=submit [NC,L]

以上规则应适用于网址: example.com/google.com

但是,虽然网址example.com/google.com仍然在浏览器栏中,但我没有收到404或500服务器错误,而是添加了google.com作为参数,{}添加了send.php作为参数代替。

网址应该转到: send.php?url=google.com&name=&submit=submit 但它目前是: send.php?url=send.php&name=&submit=submit

有趣的是,如果我稍微更改RewriteRule,一切正常。 工作RewriteRule RewriteRule ^send/(.*)$ /send.php?url=$1&name=&submit=submit [NC,L]

以下是RewriteRule的工作版本和非工作版本的日志副本。
登录(工作)RewriteRule ^send/(.*)$ /send.php?url=$1&name=&submit=submit [NC,L]

[Tue Oct 11 11:03:09.500902 2016] [rewrite:trace3] [pid 6376:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:14876] 127.0.0.1 - [example.com / sid#611988] [摆脱#2f16c40 / initial] [perdir C:/ xampp / htdocs / test /]添加路径信息后缀:C:/ xampp / htdocs / test / send - > C:/xampp/htdocs/test/send/google.com

[Tue Oct 11 11:03:09.500902 2016] [rewrite:trace3] [pid 6376:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:14876] 127.0.0.1 - [example.com / sid#611988] [rid#2f16c40 / initial] [perdir C:/ xampp / htdocs / test /] strip per-dir prefix:C:/xampp/htdocs/test/send/google.com - >发送/ google.com

[Tue Oct 11 11:03:09.500902 2016] [rewrite:trace3] [pid 6376:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:14876] 127.0.0.1 - [example.com / sid#611988] [摆脱#2f16c40 / initial] [perdir C:/ xampp / htdocs / test /]应用模式' ^ send /(.*)$'到uri'发送/ google.com'

[Tue Oct 11 11:03:09.500902 2016] [rewrite:trace2] [pid 6376:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:14876] 127.0.0.1 - [example.com / sid#611988] [摆脱#2f16c40 / initial] [perdir C:/ xampp / htdocs / test /]重写'发送/ google.com' - > ' /send.php URL = google.com&安培;名称=安培;提交=提交'

[Tue Oct 11 11:03:09.500902 2016] [rewrite:trace3] [pid 6376:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:14876] 127.0.0.1 - [example.com / sid#611988] [摆脱#2f16c40 / initial] split uri = / send.php?url = google.com& name =& submit = submit - > uri = / send.php,args = url = google.com& name =& submit = submit

登录(不工作)RewriteRule ^(.*)$ send.php?url=$1&name=&submit=submit [NC,L]

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3314c38 / initial] [perdir C:/ xampp / htdocs / test /] strip per-dir prefix:C:/xampp/htdocs/test/google.com - > google.com

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3314c38 / initial] [perdir C:/ xampp / htdocs / test /]应用模式' ^(。*)$'到uri' google.com'

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace2] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3314c38 / initial] [perdir C:/ xampp / htdocs / test /]重写' google.com' - > ' send.php URL = google.com&安培;名称=安培;提交=提交'

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3314c38 / initial] split uri = send.php?url = google.com& name =& submit = submit - > uri = send.php,args = url = google.com& name =& submit = submit

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3314c38 / initial] [perdir C:/ xampp / htdocs / test /] add per-dir prefix:send.php - > C:/xampp/htdocs/test/send.php

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace2] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3314c38 / initial] [perdir C:/ xampp / htdocs / test /] strip document_root prefix:C:/xampp/htdocs/test/send.php - > /send.php

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace1] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3314c38 / initial] [perdir C:/ xampp / htdocs / test /]使用/send.php进行内部重定向[内部重定向]

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#331af78 / initial / redir#1] [perdir C:/ xampp / htdocs / test /] strip per-dir prefix:C:/xampp/htdocs/test/send.php - > send.php

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#331af78 / initial / redir#1] [perdir C:/ xampp / htdocs / test /]应用模式' ^(。*)$'到uri' send.php'

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace2] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#331af78 / initial / redir#1] [perdir C:/ xampp / htdocs / test /]重写' send.php' - > ' send.php URL = send.php&安培;名称=安培;提交=提交'

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#331af78 / initial / redir#1] split uri = send.php?url = send.php& name =& submit = submit - > uri = send.php,args = url = send.php& name =& submit = submit

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#331af78 / initial / redir#1] [perdir C:/ xampp / htdocs / test /] add per-dir prefix:send.php - > C:/xampp/htdocs/test/send.php

[Tue Oct 11 11:21:58.485476 2016] [rewrite:trace1] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#331af78 / initial / redir#1] [perdir C:/ xampp / htdocs / test /]初始URL等于重写的URL:C:/xampp/htdocs/test/send.php [IGNORING REWRITE]

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3316c40 / initial] [perdir C:/ xampp / htdocs / test /]添加路径信息后缀:C:/ xampp / htdocs / test / css - > C:/xampp/htdocs/test/css/style.css,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3316c40 / initial] [perdir C:/ xampp / htdocs / test /] strip per-dir prefix:C:/xampp/htdocs/test/css/style.css - > css / style.css,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3316c40 / initial] [perdir C:/ xampp / htdocs / test /]应用模式' ^(。*)$'到uri&#c; / style.css',referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace2] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3316c40 / initial] [perdir C:/ xampp / htdocs / test /]重写' css / style.css' - > ' send.php?url = css / style.css& name =& submit = submit',referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3316c40 / initial] split uri = send.php?url = css / style.css& name =& submit = submit - > uri = send.php,args = url = css / style.css& name =& submit = submit,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3316c40 / initial] [perdir C:/ xampp / htdocs / test /] add per-dir prefix:send.php - > C:/xampp/htdocs/test/send.php,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace2] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3316c40 / initial] [perdir C:/ xampp / htdocs / test /] strip document_root prefix:C:/xampp/htdocs/test/send.php - > /send.php,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.862783 2016] [rewrite:trace1] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3316c40 / initial] [perdir C:/ xampp / htdocs / test /]内部重定向与/send.php [内部重定向],参考文献:http://example.com/google.com

[Tue Oct 11 11:22:03.863783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3319138 / initial / redir#1] [perdir C:/ xampp / htdocs / test /] strip per-dir prefix:C:/xampp/htdocs/test/send.php - > send.php,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.863783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3319138 / initial / redir#1] [perdir C:/ xampp / htdocs / test /]应用模式' ^(。*)$'到uri' send.php',referer:http://example.com/google.com

[Tue Oct 11 11:22:03.863783 2016] [rewrite:trace2] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3319138 / initial / redir#1] [perdir C:/ xampp / htdocs / test /]重写' send.php' - > ' send.php?url = send.php& name =& submit = submit',referer:http://example.com/google.com

[Tue Oct 11 11:22:03.863783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3319138 / initial / redir#1] split uri = send.php?url = send.php& name =& submit = submit - > uri = send.php,args = url = send.php& name =& submit = submit,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.863783 2016] [rewrite:trace3] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [rid#3319138 / initial / redir#1] [perdir C:/ xampp / htdocs / test /] add per-dir prefix:send.php - > C:/xampp/htdocs/test/send.php,referer:http://example.com/google.com

[Tue Oct 11 11:22:03.863783 2016] [rewrite:trace1] [pid 5176:tid 1632] mod_rewrite.c(476):[client 127.0.0.1:15724] 127.0.0.1 - [example.com / sid#3e1988] [摆脱#3319138 / initial / redir#1] [perdir C:/ xampp / htdocs / test /]初始URL等于重写的URL:C:/xampp/htdocs/test/send.php [IGNORING REWRITE] ,referer:http://example.com/google.com

查看日志,首先得到正确的结果:url=google.com,然后进一步更改为url=send.php

总而言之,如何更改此网址:example.com/send.php?url=google.com&name=&submit=submit 到此网址:example.com/google.com

1 个答案:

答案 0 :(得分:1)

尝试:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ send.php?url=$1&name=&submit=submit [NC,L]

这样就可以避免重写现有的文件和目录。

使用-f测试文件,使用-d测试目录。 http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond