【问题标题】:redirect to index.php if i type domain name如果我输入域名,重定向到 index.php
【发布时间】:2014-03-06 17:01:13
【问题描述】:

我正在使用 zend 框架 1.12 开发一个项目 为了在 index.php 上重定向域,我使用了两个 .htaccess,一个在根目录中,一个在公共文件夹中

我的问题是,当我输入域名时,它应该在索引控制器上重定向。

文件夹结构如下

application
--configs
----application.ini
library
--Zend
public
--css
--js
--index.php
--.htaccess

.htaccess

下面是写在根.htaccess文件中

RewriteEngine on
RewriteRule (.*) public/$1

下面是写在public/.htaccess文件中

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

application/configs/application.ini

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.baseUrl = "/"

resources.session.remember_me_seconds = 864000

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "labs"
resources.db.isDefaultTableAdapter = true

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug

以上设置一切正常。但我无法在根目录中创建任何其他文件夹。 如果我创建名为 abc 的新文件夹并像 domain.com/abc 一样访问,我将无法访问。它将这视为控制器操作。

请帮助我如何解决这个问题。 为了解决这个问题,我尝试将 index.php 放在公共文件夹的根目录中。之后没有任何工作正常。

【问题讨论】:

    标签: php mysql .htaccess zend-framework mod-rewrite


    【解决方案1】:

    使用以下代码更新 .htacces

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^js/(.*)$     public/js/$1 [L]
    RewriteRule ^images/(.*)$     public/images/$1 [L]
    RewriteRule ^css/(.*)$     public/css/$1 [L]
    RewriteRule ^.*$ index.php [NC,L]
    

    【讨论】:

      【解决方案2】:

      这就是 Zend 的原理,它处理检索 url(模块)、控制器和动作。
      您可以尝试以不同的方式为分析器网址设置routing
      否则,如果要访问所有人都可以访问的文档,则可以将其公开。
      我希望它会有所帮助

      【讨论】:

        猜你喜欢
        • 2021-10-06
        • 1970-01-01
        • 2015-11-02
        • 2021-01-26
        • 2020-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-03
        相关资源
        最近更新 更多