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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!
  • ¥20 win11账户锁定时间设为0无法登录