How to enable mod_rewrite for Apache 2.2

后端 未结 15 1364
渐次进展
渐次进展 2020-11-21 07:09

I\'ve got fresh install of Apache 2.2 on my Vista machine, everything works fine, except mod rewrite.

I\'ve uncommented

LoadModule rewrite_module mo         


        
相关标签:
15条回答
  • 2020-11-21 07:24

    There are many ways how you can fix this issue, if you know the root of the issue.

    Problem 1

    Firstly, it may be a problem with your apache not having the mod_rewrite.c module installed or enabled.

    For this reason, you would have to enable it as follows

    1. Open up your console and type into it, this:

      sudo a2enmod rewrite

    2. Restart your apache server.

      service apache2 restart

    Problem 2

    1. You may also, in addition to the above, if it does not work, have to change the override rule from the apache conf file (either apache2.conf, http.conf , or 000-default file).

    2. Locate "Directory /var/www/"

    3. Change the "Override None" to "Override All"

    Problem 3

    If you get an error stating rewrite module is not found, then probably your userdir module is not enabled. For this reason you need to enable it.

    1. Type this into the console:

      sudo a2enmod userdir

    2. Then try enabling the rewrite module if still not enabled (as mentioned above).

    To read further on this, you can visit this site: http://seventhsoulmountain.blogspot.com/2014/02/wordpress-permalink-ubuntu-problem-solutions.html

    0 讨论(0)
  • 2020-11-21 07:25

    Open terminal and typin a2enmod rewrite, It will enable your mod_rewrite module for Apache.

    Then go to /etc/apache2/sites-available and edit default file. (For this you must have writable permissions to this file and sites-available folder.)

    Replace below with existing lines 4 to 14

    DocumentRoot /var/www
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    </Directory>
    <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>
    

    Now restart your apache by /etc/init.d/apache2 restart or service apache2 restart

    Take clean URL test again and this time it will be passed.

    0 讨论(0)
  • 2020-11-21 07:28

    Old thread, just want to put that don't set AllowOverride to all instead use specific mod you want to use,

    AllowOverride mod_rewrite mod_mime
    

    And this line should be un-commented

    LoadModule rewrite_module modules/mod_rewrite.so
    

    Refrences

    • http://www.eschrade.com/page/why-you-should-not-use-htaccess-allowoverride-all-in-production/
    • https://httpd.apache.org/docs/2.4/misc/security_tips.html
    • https://httpd.apache.org/docs/2.4/rewrite/avoid.html
    0 讨论(0)
  • 2020-11-21 07:30

    In order to use mod_rewrite you can type the following command in the terminal:

    sudo a2enmod rewrite
    

    Restart apache2 after

    sudo /etc/init.d/apache2 restart
    

    or

    sudo service apache2 restart
    

    or as per new unified System Control Way

    sudo systemctl restart apache2
    

    Then, if you'd like, you can use the following .htaccess file.

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    

    The above .htaccess file (if placed in your DocumentRoot) will redirect all traffic to an index.php file in the DocumentRoot unless the file exists.

    So, let's say you have the following directory structure and httpdocs is the DocumentRoot

    httpdocs/
        .htaccess
        index.php
        images/
            hello.png
        js/
            jquery.js
        css/
            style.css
    includes/
        app/
            app.php
    

    Any file that exists in httpdocs will be served to the requester using the .htaccess shown above, however, everything else will be redirected to httpdocs/index.php. Your application files in includes/app will not be accessible.

    0 讨论(0)
  • 2020-11-21 07:33

    There's obviously more than one way to do it, but I would suggest using the more standard:

    ErrorDocument 404 /index.php?page=404
    
    0 讨论(0)
  • 2020-11-21 07:34

    If non of the above works try editing /etc/apache2/sites-enabled/000-default

    almost at the top you will find

    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
    

    Change the AllowOverride None to AllowOverride All

    this worked for me

    0 讨论(0)
提交回复
热议问题