douxiong0668 2017-03-16 11:06 采纳率: 100%
浏览 49

Apache mod_rewrite和php

I have a slight of problem. I used simple php framework on github and have worked on it and added new functions and so on.

The framework that i have had help with is this: https://github.com/panique/mini

Everything works perfectly in a MAMP environment, but now when i was going to test it on a live website and apache environment it does not work that good. It obviously can read the index file since i point the directory to the directory that should be used for apache.

But when i am going to make a call to a controller (domain.com/login) it results in apache giving me :

"Not Found: The requested URL /login was not found on this server."

I have enabled rewrite with: service a2enmod rewrite, and i double checked and it is a Loaded module when looking in phpinfo().

The .htaccess file that is located in the "/var/www/html/php-project/public" directory(where i have pointed to in my virtual host file" is the following:

# Necessary to prevent problems when using a controller named "index" and having a root index.php
Options -MultiViews

# Activates URL rewriting
RewriteEngine On

# Prevent people from looking directly into folders
Options -Indexes

# If the following conditions are true, then rewrite the URL:
# If the requested filename is not a directory,

RewriteCond %{REQUEST_FILENAME} !-d
# and if the requested filename is not a regular file that exists,
RewriteCond %{REQUEST_FILENAME} !-f
# and if the requested filename is not a symbolic link,
RewriteCond %{REQUEST_FILENAME} !-l
# then rewrite the URL in the following way:
# Take the whole request filename and provide it as the value of a
# "url" query parameter to index.php. Append any query string from
# the original URL as further query parameters (QSA), and stop
# processing this .htaccess file (L).
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

00-default.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName www.domain.com
        ServerAlias domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/php-project/public
        <Directory />
                AllowOverride All
        </Directory>
        #DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

apache.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/html/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>

AccessFileName .htaccess

I dont think the problem is within the php itself. Thats why i don't added my code since its so many classes, but the code is as i said based on the framework in the beginning of the question.

Do any of you see any obvious problems in the conf's? I have searched and searched for answers, but i don't seem to get it right. So i would really really appreciate some help. Any questions, just ask on. Thanks

  • 写回答

1条回答 默认 最新

  • dongmian8108 2017-03-16 14:31
    关注

    Please follow the proper way of access rewrite module in apache2.

    First enable the rewrite module in apache using below command-:

    $ sudo a2enmod rewrite
    

    Open the apache2.conf file

    $ nano /etc/apache2/apache2.conf
    

    Update the section

    <Directory /var/www/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>
    

    Remove the section from 00-default.conf Remove the below lines

             <Directory />
                    AllowOverride All
            </Directory>
    

    Then finally restart your apache2.

    $ sudo service apache2 restart
    

    or

    $ sudo /etc/init.d/apache2 restart
    
    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系