Can';无法在apache2中启用.htaccess

Can';无法在apache2中启用.htaccess,apache,.htaccess,ubuntu,ubuntu-12.04,vps,Apache,.htaccess,Ubuntu,Ubuntu 12.04,Vps,我有一个运行ubuntu 12.04的VPS。我已经安装了apache2,它可以从虚拟主机上毫无问题地提供网页。我现在需要启用.htaccess文件,但无法使其工作 my.htaccess文件与apache显示的index.php文件位于同一目录中。我已经将垃圾数据添加到.htaccess文件中,这样当我让它工作时,它应该会显示一个500内部服务器错误 我编辑了文件/etc/apache2/sites available/default,并在/var/www目录中将allowveride设置为A

我有一个运行ubuntu 12.04的VPS。我已经安装了apache2,它可以从虚拟主机上毫无问题地提供网页。我现在需要启用.htaccess文件,但无法使其工作

my.htaccess文件与apache显示的index.php文件位于同一目录中。我已经将垃圾数据添加到.htaccess文件中,这样当我让它工作时,它应该会显示一个500内部服务器错误

我编辑了文件/etc/apache2/sites available/default,并在/var/www目录中将
allowveride
设置为
All
,然后使用
sudo服务apache2 restart

据我所知,这应该足以处理.htaccess文件。但是,当我访问我的网页时,我没有看到500内部服务器错误,而是看到index.php文件的内容,因此似乎没有使用.htaccess文件

这是我的/etc/apache2/sites available/default文件

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        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

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

服务器管理员webmaster@localhost
DocumentRoot/var/www
选项如下符号链接
不允许超限
选项索引跟随符号链接多视图
允许超越所有
命令允许,拒绝
通融
ScriptAlias/cgi-bin//usr/lib/cgi-bin/
不允许超限
选项+执行CGI-多视图+符号链接所有者匹配
命令允许,拒绝
通融
ErrorLog${APACHE_LOG_DIR}/error.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
别名/doc/“/usr/share/doc/”
选项索引多视图跟随符号链接
不允许超限
命令拒绝,允许
全盘否定
允许从127.0.0.0/255.0.0.0::1/128开始
/etc/apache2/apache2.conf

#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.2/ for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the 'global environment').
#  2. Directives that define the parameters of the 'main' or 'default' server,
#     which responds to requests that aren't handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "foo.log"
# with ServerRoot set to "/etc/apache2" will be interpreted by the
# server as "/etc/apache2/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
LockFile ${APACHE_LOCK_DIR}/accept.lock

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5

##
## Server-Pool Size Regulation (MPM specific)
## 

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
#              graceful restart. ThreadLimit can only be changed by stopping
#              and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
# It is also possible to omit any default MIME type and let the
# client's browser guess an appropriate action instead. Typically the
# browser will decide based on the file's extension then. In cases
# where no good assumption can be made, letting the default MIME type
# unset is suggested  instead of forcing the browser to accept
# incorrect  metadata.
#
DefaultType None


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

# Include all the user configurations:
Include httpd.conf

# Include ports listing
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/
#
#基于Rob McCool最初提供的NCSA服务器配置文件。
#
#这是主要的Apache服务器配置文件。它包含
#为服务器提供指令的配置指令。
#看http://httpd.apache.org/docs/2.2/ 有关
#指令。
#
#不要在没有理解的情况下简单地阅读这里的说明
#他们做什么。它们在这里只是作为提示或提醒。如果你不确定
#查阅在线文档。你已经被警告了。
#
#配置指令分为三个基本部分:
#  1. 将Apache服务器进程的操作控制为
#整体(“全球环境”)。
#  2. 定义“主”或“默认”服务器参数的指令,
#它响应虚拟主机未处理的请求。
#这些指令还提供设置的默认值
#在所有虚拟主机中。
#  3. 虚拟主机的设置,允许将Web请求发送到
#不同的IP地址或主机名,并由
#相同的Apache服务器进程。
#
#配置和日志文件名:如果您为许多
#在服务器的控制文件中,以“/”开头(对于Win32,则为“驱动器:/”)
#服务器将使用该显式路径。如果文件名*不*开始
#在“/”前面加上ServerRoot的值——所以是“foo.log”
#当ServerRoot设置为“/etc/apache2”时,将由
#服务器名为“/etc/apache2/foo.log”。
#
###第1节:全球环境
#
#本节中的指令影响Apache的整体操作,
#例如,它可以处理的并发请求的数量或它可以处理的位置
#可以找到它的配置文件。
#
#
#ServerRoot:目录树的顶部,服务器的
#保留配置、错误和日志文件。
#
#注意!如果要将其放置在NFS(或其他网络)上
#安装的文件系统然后请阅读LockFile文档(可用
#at);
#你会省去很多麻烦。
#
#不要在目录路径的末尾添加斜杠。
#
#ServerRoot“/etc/apache2”
#
#接受序列化锁定文件必须存储在本地磁盘上。
#
LockFile${APACHE\u LOCK\u DIR}/accept.LOCK
#
#PidFile:服务器应在其中记录其进程的文件
#启动时的标识号。
#这需要在/etc/apache2/envvars中设置
#
PidFile${APACHE_PID_文件}
#
#超时:接收和发送超时之前的秒数。
#
超时300
#
#KeepAlive:是否允许持久连接(超过
#每个连接一个请求)。设置为“关闭”以停用。
#
继续
#
#MaxKeepAliverRequests:允许的最大请求数
#在持久连接期间。设置为0以允许无限量。
#我们建议您将此数字保持在较高水平,以获得最佳性能。
#
MaxKeepAliveRequests 100
#
#KeepAliveTimeout:等待来自的下一个请求的秒数
#同一连接上的同一客户端。
#
保持超时
##
##服务器池大小调节(特定于MPM)
## 
#预工作MPM
#StartServers:要启动的服务器进程数
#MinSpareServers:保留备用的最小服务器进程数
#MaxSpareServers:保留备用的最大服务器进程数
#MaxClient:允许启动的最大服务器进程数
#MaxRequestsPerChild:服务器进程服务的最大请求数
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
#工人MPM
#StartServers:要启动的服务器进程的初始数目
#MinSpareThreads:保留备用的最小工作线程数
#MaxSpareThreads:保留备用的最大工作线程数
#ThreadLimit:ThreadsPerChild可以在运行期间更改为此最大值
#优雅的重启。ThreadLimit只能通过停止来更改
#启动Apache。
#ThreadsParchild:每个服务器进程中工作线程的固定数量
#马克斯:马
<IfModule mod_rewrite.c>  
   RewriteEngine on  
   RewriteRule  ^$ app/webroot/  [L]  
   RewriteRule  (.*) app/webroot/$1 [L]  
 </IfModule>
 <IfModule mod_rewrite.c>  
    RewriteEngine on  
    RewriteRule  ^$  webroot/  [L]  
    RewriteRule  (.*) webroot/$1  [L]  
 </IfModule> 
a2enmod rewrite
service apache2 restart