重写 url,将查询字符串转换为目录路径,并从 url 中删除 cgi 脚本文件名和路径

发布于 2024-10-18 10:40:05 字数 4533 浏览 6 评论 0原文

我正在尝试重写: repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

repo.pointfree.net/remixbot/summary/例如。

...但 url 显然没有被重写(当我访问 repo.pointfree.net 时,我收到 Error 403 Forbidden)。这是我在 /home/public/werc/sites/repo.pointfree.net 中的 .htaccess

DirectoryIndex darcsweb/darcsweb.cgi
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^/darcsweb/darcsweb.cgi /darcsweb/%1/%2?

这是 .htaccess 在 < code>/home/public/:

Options +ExecCGI
AddHandler cgi-script .cgi
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^repo\.pointfree\.net$
RewriteRule (.*) /home/public/werc/sites/%{HTTP_HOST}/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /home/public/werc/bin/werc.cgi

RewriteRule /werc.cgi /f5/pointfree/public/werc/bin/werc.cgi
ErrorDocument 404 /werc.cgi

我在 /home/public/werc/sites/repo.pointfree.net/ 到 /home/public/darcsweb 中有一个名为darcsweb 的符号链接,

如有任何帮助,我们将不胜感激。

谢谢, Andreas

编辑,应用 Andreas Gohr 的建议并访问 repo.pointfree.net/remixbox/summary/ 后,我在日志文件和浏览器中看到了 404 页面。

[Mon Feb 21 00:15:28 2011] [error] [client 172.17.0.144] NOT FOUND: repo.pointfree.net/favicon.ico - http://repo.pointfree.net/remixbot/summary/ - Uzbl (Webkit 1.2) (Linux i686 [i686]), referer: http://repo.pointfree.net/remixbot/summary/
[Mon Feb 21 00:15:28 2011] [error] [client 172.17.0.144] repo.pointfree.net/favicon.ico - Uzbl (Webkit 1.2) (Linux i686 [i686]) - GET - tpl_handler lib/404.tpl - lib/default_master.tpl, referer: http://repo.pointfree.net/remixbot/summary/

当我将 favicon.ico 复制到 /home/public/ 时,我得到:

[Mon Feb 21 00:17:46 2011] [error] [client 172.17.0.131] NOT FOUND: repo.pointfree.net/remixbot/summary/ -  - Uzbl (Webkit 1.2) (Linux i686 [i686])
[Mon Feb 21 00:17:47 2011] [error] [client 172.17.0.131] repo.pointfree.net/remixbot/summary/ - Uzbl (Webkit 1.2) (Linux i686 [i686]) - GET - tpl_handler lib/404.tpl - lib/default_master.tpl

我还查看了 rewrite_log 的输出,并且没有提及darcsweb(短路?):

172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] strip document_root prefix: /f5/pointfree/public/werc/bin/werc.cgi -> /werc/bin/werc.cgi
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (1) [perdir /f5/pointfree/public/] internal redirect with /werc/bin/werc.cgi [INTERNAL REDIRECT]
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite 'index.cgi' -> '/home/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite '/home/public/werc/bin/werc.cgi' -> '/f5/pointfree/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] strip document_root prefix: /f5/pointfree/public/werc/bin/werc.cgi -> /werc/bin/werc.cgi
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (1) [perdir /f5/pointfree/public/] internal redirect with /werc/bin/werc.cgi [INTERNAL REDIRECT]
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite 'index.pl' -> '/home/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite '/home/public/werc/bin/werc.cgi' -> '/f5/pointfree/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] strip document_root prefix: /f5/pointfree/public/werc/bin/werc.cgi -> /werc/bin/werc.cgi
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (1) [perdir /f5/pointfree/public/] internal redirect with /werc/bin/werc.cgi [INTERNAL REDIRECT]
172.17.0.132 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a5f0058/initial] (1) [perdir /f5/pointfree/public/] pass through /f5/pointfree/public/favicon.ico

I am trying to rewrite: repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

as repo.pointfree.net/remixbot/summary/ for example.

...but the url is apparently not being rewritten (when I visit repo.pointfree.net I get Error 403 Forbidden). Here is my .htaccess in the /home/public/werc/sites/repo.pointfree.net:

DirectoryIndex darcsweb/darcsweb.cgi
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^/darcsweb/darcsweb.cgi /darcsweb/%1/%2?

Here is the .htaccess in /home/public/:

Options +ExecCGI
AddHandler cgi-script .cgi
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^repo\.pointfree\.net$
RewriteRule (.*) /home/public/werc/sites/%{HTTP_HOST}/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /home/public/werc/bin/werc.cgi

RewriteRule /werc.cgi /f5/pointfree/public/werc/bin/werc.cgi
ErrorDocument 404 /werc.cgi

I have a symlink in /home/public/werc/sites/repo.pointfree.net/ to /home/public/darcsweb named darcsweb

any help on this would be appreciated.

Thanks,
Andreas

EDIT, After applying Andreas Gohr's suggestion and visiting repo.pointfree.net/remixbox/summary/ I got this in my log file and a my 404 page in the browser.

[Mon Feb 21 00:15:28 2011] [error] [client 172.17.0.144] NOT FOUND: repo.pointfree.net/favicon.ico - http://repo.pointfree.net/remixbot/summary/ - Uzbl (Webkit 1.2) (Linux i686 [i686]), referer: http://repo.pointfree.net/remixbot/summary/
[Mon Feb 21 00:15:28 2011] [error] [client 172.17.0.144] repo.pointfree.net/favicon.ico - Uzbl (Webkit 1.2) (Linux i686 [i686]) - GET - tpl_handler lib/404.tpl - lib/default_master.tpl, referer: http://repo.pointfree.net/remixbot/summary/

and when I copy a favicon.ico to /home/public/ I get:

[Mon Feb 21 00:17:46 2011] [error] [client 172.17.0.131] NOT FOUND: repo.pointfree.net/remixbot/summary/ -  - Uzbl (Webkit 1.2) (Linux i686 [i686])
[Mon Feb 21 00:17:47 2011] [error] [client 172.17.0.131] repo.pointfree.net/remixbot/summary/ - Uzbl (Webkit 1.2) (Linux i686 [i686]) - GET - tpl_handler lib/404.tpl - lib/default_master.tpl

I have also looked at the output of rewrite_log and there is no mention of darcsweb (short-circuit?):

172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] strip document_root prefix: /f5/pointfree/public/werc/bin/werc.cgi -> /werc/bin/werc.cgi
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (1) [perdir /f5/pointfree/public/] internal redirect with /werc/bin/werc.cgi [INTERNAL REDIRECT]
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite 'index.cgi' -> '/home/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite '/home/public/werc/bin/werc.cgi' -> '/f5/pointfree/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] strip document_root prefix: /f5/pointfree/public/werc/bin/werc.cgi -> /werc/bin/werc.cgi
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (1) [perdir /f5/pointfree/public/] internal redirect with /werc/bin/werc.cgi [INTERNAL REDIRECT]
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite 'index.pl' -> '/home/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] rewrite '/home/public/werc/bin/werc.cgi' -> '/f5/pointfree/public/werc/bin/werc.cgi'
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (2) [perdir /f5/pointfree/public/] strip document_root prefix: /f5/pointfree/public/werc/bin/werc.cgi -> /werc/bin/werc.cgi
172.17.0.131 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a43a058/subreq] (1) [perdir /f5/pointfree/public/] internal redirect with /werc/bin/werc.cgi [INTERNAL REDIRECT]
172.17.0.132 - - [21/Feb/2011:03:49:13 +0000] [repo.pointfree.net/sid#286c26a0][rid#2a5f0058/initial] (1) [perdir /f5/pointfree/public/] pass through /f5/pointfree/public/favicon.ico

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜清冷一曲。 2024-10-25 10:40:05

在我看来,你的重写方式是错误的。如果我理解正确的话,您希望能够使用像 repo.pointfree.net/remixbot/summary/ 这样的 URL 来访问真正的 repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

您的重写应该看起来像这样:

RewriteRule ^\/(.+?)\/(.+?)\/?   /darcsweb/darcsweb.cgi?r=$1;a=$2 [QSA]

然而这只是事情的一半。当发出这样的请求时,它会告诉 Apache 在哪里查找,但它不会告诉您的应用程序创建这些漂亮的 URL。除非你想破解 CGI(或者它有一个选项),否则你可能无能为力。

除非...也许重定向会起作用:

RewriteRule ^\/(.+?)\/(.+?)\/?   /darcsweb/darcsweb.cgi?r=$1;a=$2 [QSA,L]
RewriteRule ^\/darcsweb\/darcsweb.cgi?r=(.+?);a=(.+?) /$1/$2/ [QSA,R]

这会导致每次您单击应用程序中的链接时重定向到干净的 URL...

PS:您可能需要考虑使用 http://blitiri.com.ar/p/darcsweb/ 而不是简单的darcs CGI。

It seems to me that you got the rewrite the wrong way round. If I understand you correctly you want to be able to use a URL like repo.pointfree.net/remixbot/summary/ to access what is really repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

Your rewrite should look something like this then:

RewriteRule ^\/(.+?)\/(.+?)\/?   /darcsweb/darcsweb.cgi?r=$1;a=$2 [QSA]

However this is only half of the thing. It will tell Apache where to look when such a request is posted, but it doesn't tell your application to create these nice URLs. Unless you want to hack the CGI (or it has an option for it) there is probably not much you can do.

Except... maybe a redirect would work:

RewriteRule ^\/(.+?)\/(.+?)\/?   /darcsweb/darcsweb.cgi?r=$1;a=$2 [QSA,L]
RewriteRule ^\/darcsweb\/darcsweb.cgi?r=(.+?);a=(.+?) /$1/$2/ [QSA,R]

This would cause a redirect to the clean URL everytime you click a link in your application...

PS: you might want to consider using http://blitiri.com.ar/p/darcsweb/ instead of the simple darcs CGI.

橪书 2024-10-25 10:40:05

为什么 URL 中本应是 & 符号的地方却出现了分号?

repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

上面不应该是

repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot&a=summary

另外,这个RewriteRule怎么样?

RewriteRule ^darcsweb/darcsweb.cgi?r=(.+)&a=(.+)$ /$1/$2/

作为调试辅助工具,请尝试删除 RewriteCond 以确保它没有任何问题。

Why is there a semicolon where it should've been an ampersand in your URL?

repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

shouldn't the above be

repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot&a=summary

Also, how about this RewriteRule?

RewriteRule ^darcsweb/darcsweb.cgi?r=(.+)&a=(.+)$ /$1/$2/

As a debugging aid, try once by removing the RewriteCond to ensure that there's nothing wrong with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文