【问题标题】:How to redirect from subfolder with .htaccess?如何使用 .htaccess 从子文件夹重定向?
【发布时间】:2013-08-23 06:44:03
【问题描述】:

我有一些问题要问你,请原谅我。当我想将我的网站重定向到另一个位置时,我遇到了一些麻烦。我尝试的网址是这样的:

http://localhost/mywebsite/public/example.html  => Default URL

我想将我的默认网址重定向到这里:

http://localhost/mywebsite/example.html => What i want

我的 .htaccess 代码是:

Redirect 301 public /

我正在使用 laravel 框架

【问题讨论】:

    标签: php .htaccess redirect frameworks laravel


    【解决方案1】:

    如果您希望重定向是透明的,即/public 仍然隐藏在 URL 中,请不要执行 301,因为它执行外部重定向。请改用以下RedirectRule

    RewriteCond %{REQUEST_URI} !/public/ [NC]
    RedirectRule ^mywebsite/(.*)$ mywebsite/public/$1 [NC,L]
    

    这将从/mywebsite/public/page.html 默默地为/mywebsite/page.html 提供服务。

    【讨论】:

    • 这在我的页面中不起作用,我收到 500 服务器错误,您还有其他想法吗?
    • 如果使用 rewriterule 会怎样?
    • @ArryanggaAlievPratamaputra 添加我刚刚更新的重写条件。
    【解决方案2】:

    将您的 .htaccess 文件放入“public”文件夹:

         RewriteEngine on
         RewriteRule (.*)$ /mywebsite/$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-20
      • 2021-06-13
      相关资源
      最近更新 更多