Apache重写规则未按预期工作
我有两台apache服务器,它们都有相同的设置,我克隆了apache配置文件,只更改了ServerName部分。当我键入mysite.com/something时,它应该重写为index.php,它在我的旧服务器上执行,但在我的新服务器上不执行。我已经确保当我使用mysite.com/index.php/something时,可以使用.htaccess,但是就像我的第一个站点一样,我需要它来使用mysite.com/something 这是我的.htaccess和apache配置文件Apache重写规则未按预期工作,apache,.htaccess,zend-framework,mod-rewrite,ubuntu,Apache,.htaccess,Zend Framework,Mod Rewrite,Ubuntu,我有两台apache服务器,它们都有相同的设置,我克隆了apache配置文件,只更改了ServerName部分。当我键入mysite.com/something时,它应该重写为index.php,它在我的旧服务器上执行,但在我的新服务器上不执行。我已经确保当我使用mysite.com/index.php/something时,可以使用.htaccess,但是就像我的第一个站点一样,我需要它来使用mysite.com/something 这是我的.htaccess和apache配置文件 #.hta
#.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>
#.htaccess文件
选项+FollowSymlinks
重新启动发动机
RewriteCond%{ENV:REDIRECT_STATUS}^$
重写规则^app\.php(/(.*)|$)%{CONTEXT_PREFIX}/$2[R=301,L]
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
RewriteCond%{REQUEST_URI}:$1^(/.+)(.+):\2$
重写规则^(.*)-[E=基:%1]
重写规则.?%{ENV:BASE}index.php/[L]
重定向匹配302^/$/index.php/
标题集访问控制允许原点“*”
现在来看我的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>
服务器管理员user@host.com
服务器名mysite.com
DocumentRoot/home/richardw/www/halogon/web
选项如下符号链接
允许超越所有
选项索引跟随符号链接多视图
允许超越所有
命令允许,拒绝
通融
ErrorLog${APACHE_LOG_DIR}/error.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
如果这是转发,我深表歉意,但我一直在搜索,我即将丢失它。您是否尝试评论或删除此行
Options+FollowSymlinks
在您的.htaccess中
当您转到
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>
重定向匹配302^/$/index.php/
这实际上是说“如果mod_rewrite未加载”,那么如果加载了mod_alias,它会将根请求重定向到
/index.php/
。因此,如果发生重定向,当您转到http://mysite.com/
,是否重定向到http://mysite.com/index.php/
?是的,就是这样:/。我发誓是我做的,但我没打好。ln-s/etc/apache2/mods可用/rewrite.load/etc/apache2/mods启用/rewrite.load