首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重写url,将querystring转换为目录路径,并从url中删除cgi脚本文件名和路径。

重写url,将querystring转换为目录路径,并从url中删除cgi脚本文件名和路径。
EN

Stack Overflow用户
提问于 2011-02-20 21:29:41
回答 2查看 2.4K关注 0票数 1

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

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

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

代码语言:javascript
复制
DirectoryIndex darcsweb/darcsweb.cgi
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^/darcsweb/darcsweb.cgi /darcsweb/%1/%2?

这是.htaccess in /home/public/

代码语言:javascript
复制
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/site/repo.pointFree.net/ to /home/public/darcsweb中有一个名为darcsweb的符号链接。

如能对此提供任何帮助,将不胜感激。

谢谢,安德烈亚斯

编辑,在应用Andreas的建议并访问repo.pointFree.net/remixbox//我的日志文件和浏览器中的404页中得到了这个结果。

代码语言:javascript
复制
[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/我得到:

代码语言:javascript
复制
[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 (短路?):

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-20 22:07:23

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

您的重写应该如下所示:

代码语言:javascript
复制
RewriteRule ^\/(.+?)\/(.+?)\/?   /darcsweb/darcsweb.cgi?r=$1;a=$2 [QSA]

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

除了..。也许重定向会有效果:

代码语言:javascript
复制
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。

票数 1
EN

Stack Overflow用户

发布于 2011-02-20 21:43:32

为什么你的URL中有个分号应该是一个符号呢?

代码语言:javascript
复制
repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot;a=summary

以上不应该是

代码语言:javascript
复制
repo.pointfree.net/darcsweb/darcsweb.cgi?r=remixbot&a=summary

还有,这个RewriteRule怎么样?

代码语言:javascript
复制
RewriteRule ^darcsweb/darcsweb.cgi?r=(.+)&a=(.+)$ /$1/$2/

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5060171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档