doujiao7483 2017-02-17 14:11 采纳率: 0%
浏览 103
已采纳

Apache mod_rewrite不起作用

I want use mod_rewrite but seems that is not working, I activated it and I setup in my .htaccess but nothing seems to work. I want to NOT display index.php in my URL : instead of

localhost/index.php/admin/login

I want to display

localhost/admin/login

I am under Ubuntu Here is what my phpinfo() says :

enter image description here

This is my .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>

This is my /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条回答 默认 最新

  • dqdl6469 2017-02-20 09:37
    关注

    I figured out that I had to config the apache2.conf file /etc/apache2/apache2.conf and change

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

    to

    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All  <<--Activate rewriting
        Require all granted
    </Directory>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器