【问题标题】:PHP MVC .htaccess redirectPHP MVC .htaccess 重定向
【发布时间】:2017-09-16 11:11:43
【问题描述】:

我想用 PHP 编写一个 MVC 应用程序并具有以下文件结构:

<pre>
/
|-- application
|   |
|   ...
|
|-- public
|   |-- css
|   |   |-- screen.css
|   |   `-- print.css
|   |-- scripts
|   |   `-- wlan.sh
|   |-- bugfixes
|   |   `-- audiofix.sh
|   `-- index.php
`-- .htaccess
</pre>

这是我的.htaccess 文件:

RewriteEngine On
RewriteBase /public

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/index.php [L]

什么有效:

  • 在不更改 URI 的情况下将“/something”之类的虚拟 URI 重定向到“/public/index.php”
  • 在不更改 URI 的情况下将文件 URI(如“/css/screen.css”)重定向到“/public/css/screen.css”

什么不起作用:

  • 将目录 URI(如“/scripts”)重定向到“/public/index.php”而不是“/public/scripts”

我什么都试过了。我该怎么做?

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    解决办法是:

    RewriteEngine On
    
    # Stop processing if already in the /public directory
    RewriteRule ^public/ - [L]
    
    # Static resources if they exist
    RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
    RewriteRule (.+) public/$1 [L]
    
    # Route all other requests
    RewriteRule (.*) public/index.php [L]
    

    感谢:MVC public folder htaccess is not working

    【讨论】:

      猜你喜欢
      • 2013-06-30
      • 2017-07-13
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多