我正在尝试创建一个重写规则,将带参数的URL更改为正斜杠后跟参数 .
重写规则: RewriteRule ^(.*)$ send.php?url=$1&name=&submit=submit [NC,L]
以上规则应适用于URL: example.com/google.com
但是,虽然URL example.com/google.com
仍保留在浏览器栏中,但我没有收到404或500服务器错误,而是添加了google.com作为参数,而是添加 send.php
作为URL参数 .
该URL应该转到: 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 - > 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] [摆脱#2f16c40 / initial] [perdir C:/ xampp / htdocs / test /]将模式'^ send /(.*)$'应用到uri'send / 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 /]重写'send / google.com' - >'/ append.php?url=google.com&name=&submit=submit'
[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&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] [摆脱#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&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] 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 'css/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进行内部重定向[INTERNAL REDIRECT],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 /] 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] [rid#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
总而言之,如何将此URL: example.com/send.php?url=google.com&name=&submit=submit
转换为此URL: example.com/google.com
1 回答
试试:
这样就可以避免重写现有的文件和目录 .
使用
-f
进行文件测试,使用-d
进行目录测试 . http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond