Apache mod_rewrite不起作用

时间:2017-02-17 14:11:14

标签: php apache .htaccess mod-rewrite

我想使用mod_rewrite但似乎无法正常工作,我激活它并在我的.htaccess中设置但似乎没有任何效果。 我想在我的网址中不显示index.php: 而不是

localhost/index.php/admin/login

我想要显示

localhost/admin/login

我在Ubuntu下 这是我的phpinfo()所说的:

enter image description here

这是我的.htaccess:

# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on

#RewriteBase /virtualpost
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITEBASE:/virtualpost]

#RewriteBase /
RewriteCond %{HTTP_HOST} ^((?!localhost).)*$
RewriteRule . - [E=REWRITEBASE:/]

# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
RewriteCond %{THE_REQUEST}              ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(system\/virtualpost\/cache|system\/codeigniter|\.git|\.hg).*$

# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_php5.c>
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

这是我的/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
    SetEnv MYSQL_DB_HOST localhost
    SetEnv MYSQL_USER root
    SetEnv MYSQL_PASSWORD spaces
    SetEnv MYSQL_DB_NAME clevvermail
    <Directory ...>
        AllowOverride All
    </Directory>
    DocumentRoot /var/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    LoadModule rewrite_module modules/mod_rewrite.so
</VirtualHost>

1 个答案:

答案 0 :(得分:1)

我发现我必须配置apache2.conf文件/etc/apache2/apache2.conf and change

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None   <<-- Rewriting desactivated
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All  <<--Activate rewriting
    Require all granted
</Directory>