【问题标题】:simple redirect using .htaccess is not working使用 .htaccess 的简单重定向不起作用
【发布时间】:2018-07-27 10:04:39
【问题描述】:

我正在尝试创建一个简单的重定向,我对user/55 的所有请求都将被重定向到 folder2/index2.html

我正在运行 wamp 的 localhost 上进行测试。 我的项目层次结构是:

我这样定义.htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^users/55 folder2/index2.html [R=301,L]

我的主页是index1.html,它看起来像这样:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>Index1 page</h1>

    <a href="users/55">go to second page</a>
 </body>
 </html>

当我按下链接时,没有重定向,而是出现错误: The requested URL /redirect/folder1/users/ was not found on this server.

我在 Apache 服务器上启用了 mod_rewrite,但我在日志中看不到错误。 我做错了什么我尝试遵循一个简单的指南,但它不起作用。

【问题讨论】:

  • .htacess 应该是.htaccess
  • @Pieter 原谅我的错字

标签: javascript html .htaccess


【解决方案1】:

我认为这只是因为你的锚标签中的 url 是一个相对 url。

<a href="users/55">go to second page</a>

以上将链接到/redirect/folder1/users/

如果你想链接到/redirect/users你可以试试

 <a href="/redirect/users/55">go to second page</a>

【讨论】:

  • 我按照你的建议做了,但我现在被重定向到 http://localhost/folder2/index2.html 而不是 http://localhost/redirect/folder2/index2.html 你知道为什么吗?
  • 这是您的重定向问题。尝试将RewriteRule ^users/55 folder2/index2.html [R=301,L] 更改为RewriteRule ^users/55 redirect/folder2/index2.html [R=301,L]
  • hmmmmm 不确定这怎么可能。重写规则是否会在不重新启动服务器的情况下应用?
  • 是的,他们这样做了,我还尝试重新启动服务器并清除浏览数据,注意帮助好像redirect/ 部分被忽略,我被重定向到localhost/folder2/index2.html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-07
相关资源
最近更新 更多