【问题标题】:Apache htaccess sending URLs in a URLApache htaccess 在 URL 中发送 URL
【发布时间】:2015-02-04 13:53:53
【问题描述】:

我正在尝试在一个URL中发送一个URL,中间有ModRewrite。

这是重写规则。它用于搜索用户的个人资料。

RewriteEngine On RewriteRule ^(query)/(profile)/([a-z0-9:.()\-\ ]+)/?$ search/index.php?scope=$2&query=$3 [NC,L]

这是网址

http://www.example.com/query/profile/http://www.facebook.com/example

无论我如何执行重写规则,我都会不断收到 NetworkError: 500 Internal Server ErrorNetworkError: 404 Not Found(如果这是我放在那里的 URL)。

我怎样才能正确地做到这一点?我使用的是 Windows 7 家庭高级版。我错过了什么吗?

上面的 URL 是使用 ajax 传递的。

编辑:

#htaccess in site1 folder
RewriteRule ^resources/?(.*)/?$ /control/$1 [NC,L]

#htaccess in control folder
RewriteRule ^(query)/(profile)/([a-z0-9:.()\-\ ]+)/?$ search/index.php?scope=$2&query=$3 [NC,L]

next folder is `search` which has `index.php`

URL used
http://www.example.com/resources/query/profile/http://www.facebook.com/example

编辑: 我像下面那样重新编写了 RewriteRule,现在没有收到任何错误消息,但 Apache 似乎在 http:// 之后的 URL 中删除了一个 /。所以我只得到http:/www.facebook.com/example。任何帮助将不胜感激。

RewriteRule ^(query)/(profile)/([a-z0-9\/:.()\-\ ]+)/?$ search/index.php?scope=$2&query=$3 [NC,L]`

【问题讨论】:

  • 你能从你想重写的网址发帖到什么网址吗?

标签: apache .htaccess mod-rewrite


【解决方案1】:

您需要从 RewriteCond 捕获 URL,否则 Apache 会将多个 // 修剪为一个。

在根 .htaccess 中更改此规则:

RewriteCond %{REQUEST_URI} /resources/(.+)$ [NC]
RewriteRule ^ /control/%1 [L]

/control/.htaccess 文件中有这个:

RewriteEngine On
RewriteBase /control/

RewriteCond %{REQUEST_URI} /(query)/(profile)/(.+)$ [NC]
RewriteRule ^ /resources/search/index.php?scope=%2&query=%3 [QSA,L]

【讨论】:

  • RewriteBase / 给了我一个404 错误。我认为那是因为我的 .htaccess 在名为 search 的文件夹中。没有RewriteBase /我仍然得到404
  • 而且,你是正确的关于 Apache 修剪多个 //
  • 没有。它不是。是这样的——site1/resources/search/.htaccess
  • 我似乎几乎做对了,除了 Apache 删除了 ///
  • 啊!最后。这次工作了。谢谢你,阿努巴瓦。你是个好人......总是在那里帮助 htaccess :-)
猜你喜欢
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多