【问题标题】:htacces is not redirectinghtaccess 没有重定向
【发布时间】:2021-02-26 05:42:55
【问题描述】:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

从根目录重定向到 public/index.php 但它不起作用。本地主机是 wamp(apache)

【问题讨论】:

  • root file public ?这可能意味着什么,请显示确切的文件夹结构
  • 感谢您在问题中表现出您的努力。您能否让我们知道您想更清楚地从哪个网址重定向到哪个网址,请在您的问题中添加该信息。
  • procject(根文件夹)=>public=>index.php
  • .htaccess 这个文件在项目(根文件夹)中
  • 您的.htaccess 文件位于code 文件夹中,而不是public 文件夹中。我猜public 文件夹是你的DocumentRoot 或者至少应该是

标签: .htaccess redirect mod-rewrite url-rewriting wamp


【解决方案1】:

如果我没有正确回答您的问题,请尝试关注。这只是检查 REQUEST_URI 是否为空,然后进一步移动到 rewriterule 以将其在后端重定向到 index.php 文件

RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /public/index.php [L]

恕我直言,当您在重写器右侧使用 public/$1 时,$1 为空,因为它的 REQUEST_URI 值为 NULL,因为您正在访问基本 url,因此最好在此处写 /public/index.php

【讨论】:

  • RewriteEngine ON RewriteCond %{REQUEST_URI} ^$ RewriteRule ^(.*)$ /public/index.php [L] 它不工作
  • @yunusdjanov,你能告诉我你遇到了什么错误吗?
  • 在此服务器上找不到请求的资源/。
  • REQUEST_URI 字符串以斜杠开头。如果要匹配根目录,则条件模式应为 ^/$
  • @AmitVerma,感谢 Amit 纠正,完全错过了,谢谢,干杯,学习愉快。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-21
  • 1970-01-01
  • 2013-11-12
  • 1970-01-01
  • 2016-05-15
  • 2011-01-28
相关资源
最近更新 更多