简体   繁体   English

.htaccess文件在LAMP中不起作用

[英].htaccess file not works in LAMP

This is my .htaccess file. 这是我的.htaccess文件。 I am used Codeigniter Framework for my project. 我的项目使用Codeigniter Framework。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /project_name/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Where is my mistake here? 我的错在哪里? But It Works in xampp. 但它在xampp中有效。

You can't just move from one server to another and not make sure your prerequistes are there. 您不能只从一台服务器移动到另一台服务器,也不能确保您的先决条件在那里。 These things are not on by default on most systems. 在大多数系统上,默认情况下不启用这些功能。 You also have not given any specifics about your setup or even your document root. 您也没有提供有关设置甚至文档根目录的任何详细信息。

So going off that it's an Ubuntu server and apache2, you need to do these things. 因此,如果要使用Ubuntu服务器和apache2,则需要执行这些操作。

First thing you need to do if this is a new LAMP install is make sure rewrite is on. 如果这是新安装的LAMP,您需要做的第一件事就是确保重写已打开。

Run this command to enable mod_rewrite. 运行此命令以启用mod_rewrite。

sudo a2enmod rewrite

Then you need to make sure you allow .htaccess in your document root. 然后,您需要确保在文档根目录中允许.htaccess。

edit 编辑

/etc/apache2/sites-available/000-default.conf

In this file search for this 在此文件中搜索此

 AllowOverride None

and change it to 并将其更改为

AllowOverride All

Then restart apache2. 然后重新启动apache2。

sudo service apache2 restart

EDIT: Based on your comment, you need to make your vhost look like this and then restart apache2. 编辑:根据您的评论,您需要使您的虚拟主机看起来像这样,然后重新启动apache2。

    <VirtualHost *:80> 
    ServerAdmin webmaster@localhost 
    DocumentRoot /var/www/html 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
    <Directory /var/www/html>
      AllowOverride All
    </Directory>
    </VirtualHost>

Are you sure mod_rewrite module is loaded ? 您确定已加载mod_rewrite模块吗? go to httpd.conf and search for - 转到httpd.conf并搜索-

LoadModule rewrite_module modules/mod_rewrite.so

and make sure theres no # [hash tag] before 并确保之前没有#[hash标签]

Open your terminal Run this following code: 打开终端运行以下代码:

sudo nano /etc/apache2/apache2.conf

go down and change: 下来改变:

AllowOverride All

look like: 看起来像:

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

Then restart apache2. 然后重新启动apache2。

sudo service apache2 restart

and then .htaccess file is 然后.htaccess文件是

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

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

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