1

我有两个 apache 服务器都具有相同的设置,我克隆了 apache 配置文件,并且只更改了 ServerName 部分。当我键入 mysite.com/somestuff 它应该重写为 index.php 它在我的旧服务器上执行它,但不是我的新服务器。当我执行 mysite.com/index.php/somestuff 时,我已确保 .htaccess 存在,但就像我的第一个站点一样,我需要它与 mysite.com/somestuff 一起使用。

我真的把我的头撞到墙上是我的 .htaccess 和 apache 配置文件

#.htaccess file
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule .? %{ENV:BASE}index.php/ [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

现在对于我的 apache 配置

<VirtualHost *:80>
        ServerAdmin user@host.com
        ServerName mysite.com
        DocumentRoot /home/richardw/www/halogen/web
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /home/richardw/www/halogen/web/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

如果这是转发,我深表歉意,但我一直在寻找,我即将失去它。

4

2 回答 2

2

当你去http://mysite.com/,你被重定向到http://mysite.com/index.php/

如果发生这种情况,则意味着 mod_rewrite 未加载到您的新服务器中。您需要确保它已加载到您的 apache 的服务器配置文件中。有关如何为 apache 工作的一些说明,请参阅此答案。

重定向工作的原因是因为这个容器:

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

这实质上是说“如果加载 mod_rewrite”,那么如果加载了 mod_alias,它将根请求重定向到/index.php/. 因此,如果发生重定向,则不会加载 mod_rewrite。

于 2013-07-25T03:29:05.817 回答
0

您是否尝试
Options +FollowSymlinks
在 .htaccess 中评论或删除此行?

于 2013-07-25T01:32:45.123 回答