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 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块