Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

apache - Can't get .htaccess mod_rewrite rules to work - 404 Not Found

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

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

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

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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had a working .htaccess file that I switched over to another server. It was working fine before and stopped working after the switch. I solved the problem by configuring the httpd.conf file.

SSH onto your server and open the httpd.conf file for editing:

cd /etc/httpd/conf
sudo nano httpd.conf

find the "Directory" tag. Should look like this->

<Directory "/var/www/html">

Replace AllowOverride None with

AllowOverride All

Restart

sudo service httpd restart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...