【问题标题】:.htaccess help within root and public.htaccess 帮助在 root 和 public
【发布时间】:2019-09-10 21:57:57
【问题描述】:

我有一个小型 mvc 应用程序,我试图强制 URL 从 www.example.com 转到 www.example.com/public。

为了做到这一点,我在根目录 (/) 中有一个 .htaccess 文件,然后在 /public 文件夹中有另一个 .htaccess 文件,以使用友好的 url 指向 index.php。我相信问题出在公用文件夹中的 htaccess 文件中,我需要所有请求都通过 index.php

我在 stackoverflow 上尝试了几个线程,但是当我访问 www.example.com 时似乎给了我服务器 500 错误

根目录的.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /public/

</IfModule>

公用文件夹的.htaccess

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME}% !-f
    RewriteCond %{REQUEST_FILENAME}% !-d
    #allow images, css and js links
    RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]


    RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

</IfModule>

【问题讨论】:

  • DirectoryIndex yourindex.php
  • 我应该添加哪个部分?在根或公共 .htaccess 文件中?

标签: php .htaccess


【解决方案1】:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule (.*) /public/index.php

【讨论】:

  • 感谢 Nathan 的输入,如果我想要 www.example.com/about 我将如何添加这个?
猜你喜欢
  • 2011-04-23
  • 2010-10-29
  • 2015-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多