简体   繁体   English

Apache mod_rewrite和php

[英]Apache mod_rewrite and 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. 我在github上使用了简单的php框架并且已经开发了它并添加了新的功能等等。

The framework that i have had help with is this: https://github.com/panique/mini 我有帮助的框架是: 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. 一切都在MAMP环境中完美运行,但现在当我要在实时网站和apache环境中测试它时,它并没有那么好用。 It obviously can read the index file since i point the directory to the directory that should be used for apache. 它显然可以读取索引文件,因为我将目录指向应该用于apache的目录。

But when i am going to make a call to a controller (domain.com/login) it results in apache giving me : 但是当我要打电话给控制器(domain.com/login)时,会导致apache给我:

"Not Found: The requested URL /login was not found on this server." “未找到:在此服务器上找不到请求的URL /登录名。”

I have enabled rewrite with: service a2enmod rewrite, and i double checked and it is a Loaded module when looking in phpinfo(). 我已经启用了重写:service a2enmod rewrite,并且我在查看phpinfo()时双重检查并且它是一个Loaded模块。

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: 位于“/ var / www / html / php-project / public”目录中的.htaccess文件(我在虚拟主机文件中指向的文件)如下:

# 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 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 的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. 我不认为问题是在PHP本身。 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? 你们有没有看到conf中有任何明显的问题? 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 谢谢

Please follow the proper way of access rewrite module in apache2. 请遵循apache2中正确的访问重写模块的方法。

First enable the rewrite module in apache using below command-: 首先使用以下命令在apache中启用重写模块:

$ sudo a2enmod rewrite

Open the apache2.conf file 打开apache2.conf文件

$ 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 从00-default.conf中删除该部分删除以下行

         <Directory />
                AllowOverride All
        </Directory>

Then finally restart your apache2. 然后最后重新启动你的apache2。

$ sudo service apache2 restart

or 要么

$ sudo /etc/init.d/apache2 restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM