无法使 .htaccess mod_rewrite 规则起作用 - 404 Not Found [英] Can't get .htaccess mod_rewrite rules to work - 404 Not Found

查看:35
本文介绍了无法使 .htaccess mod_rewrite 规则起作用 - 404 Not Found的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个简单的 .htaccess 重写规则起作用,但我似乎无法解决.

I'm trying to get a simple .htaccess rewrite rule to work, but I can't seem to work it out.

我的 .htaccess 看起来像:

My .htaccess looks like:

RewriteEngine On
RewriteRule ^api$ phpinfo.php
ErrorDocument 404 /error.php

php_flag  display_errors                  on
php_flag  display_startup_errors          on
php_flag  file_uploads                    on
php_value error_reporting                 2047
php_value max_input_time                  60
php_value post_max_size                   8M
php_value upload_max_filesize             2M

当我访问 /api 时,我收到一个 404 错误,提示找不到 /api.

When I access /api, I get a 404 error saying that /api can't be found.

我的 apache conf 文件如下所示:

My apache conf file looks like:

<IfModule mod_ssl.c>
  NameVirtualHost 10.104.17.3:443
  <VirtualHost 10.104.17.3:443>
    ServerName orddev.foo.com.au
    DocumentRoot /var/www/orddev.foo.com.au___443/html
    <Directory />
      Options FollowSymLinks
      AllowOverride All
    </Directory>
    <Directory "/var/www/orddev.foo.com.au___443/html">
      Options FollowSymLinks MultiViews IncludesNOEXEC
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
    <IfModule mod_php5.c>
      php_admin_value upload_tmp_dir "/var/www/orders.foo.com.au___443/resources/_tmp/upload/"
    </IfModule>
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_METHOD} ^TRACE
      RewriteRule .* - [F]
    </IfModule>
    ErrorLog  logs/orddev.foo.com.au___443/ssl_error.log
    CustomLog logs/orddev.foo.com.au___443/ssl_access.log combinedio
    CustomLog logs/orddev.foo.com.au___443/ssl_request.log ssl
    LogLevel warn
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:!SSLv2
    SSLCertificateFile /etc/pki/tls/certs/orddev.foo.com.au.crt
    SSLCertificateKeyFile /etc/pki/tls/private/orddev.foo.com.au.key
    <Files ~ "\.(cgi|shtml|phtml|php|php3?)$">
      SSLOptions +StdEnvVars
    </Files>
    SetEnvIf User-Agent ".*MSIE.*" \
      nokeepalive ssl-unclean-shutdown \
      downgrade-1.0 force-response-1.0
  </VirtualHost>
</IfModule>

知道我做错了什么吗?我知道 .htaccess 正在被读取,就好像我更改了 404 文档一样,我收到关于 404 文档未正确设置的错误.

Any idea what I'm doing wrong? I know the .htaccess is being read as if I change the 404 document, I get an error about the 404 document not being setup properly.

推荐答案

听起来您的 apache 没有加载 mod_rewrite.

It sounds like your apache isn't loading mod_rewrite.

找到您的 httpd.conf 并搜索rewrite_module".

Locate your httpd.conf and search for "rewrite_module".

如果该行以 # 开头(使其成为注释),请删除 # 并重新启动 apache.

If that line begins with a # (making it a comment), remove the # and restart apache.

在我这里,这条线是:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

...但是YMMV.

这篇关于无法使 .htaccess mod_rewrite 规则起作用 - 404 Not Found的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆