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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵