【问题标题】:RewriteRule Equivalent [closed]RewriteRule 等效项[关闭]
【发布时间】:2012-01-10 20:03:56
【问题描述】:

下面的RewriteRule 是什么?

Redirect permanent /a.html http://www.example.com/b/

请注意,a.html 也位于同一域中,例如www.example.com

我发现使用Redirect 指令有点麻烦,因为"destination" URL cannot use a relative path

【问题讨论】:

  • 请注意,a.html 假定驻留在同一服务器上,即 example.com
  • 但是“http://www.example.com/b/”不是相对 URL 吗?
  • @symcbean:http://www.example.com/b/ 是完全限定的 URL。我正在寻找使用相对路径的解决方案,例如/b/.
  • 关闭这个问题的人能否解释一下为什么这个问题被关闭了?有 7,000 多个与 .htaccess 相关的问题,如果我错了,请纠正我,这是编程行业独有的实用且可回答的问题(引用常见问题解答)。

标签: apache .htaccess configuration apache2 configuration-files


【解决方案1】:

如果您想将 a.html 重定向到同一个域但 /b/ 目录,即 http://www.anydomain.com/a.htmlhttp://www.anydomain.com/b/,请将以下内容添加到您域根目录中的 .htaccess 文件中。

RewriteEngine On
RewriteBase /

#reirect a.html to /b/ 
RewriteRule ^a.html$ b/ [L,R=301]

【讨论】:

  • 谢谢@Ulrich!抱歉,我之前没有指定 a.html 在同一个域中;按照示例,它位于 www.example.com
  • 这很棒。在.htaccess 级别指定重写规则适用于 HTTP 和 HTTPS;如果是在虚拟主机上,您需要执行以下操作:stackoverflow.com/q/8759906/583539
猜你喜欢
  • 2012-09-03
  • 2011-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-19
  • 2010-12-04
  • 1970-01-01
相关资源
最近更新 更多