apache mod_rewrite is not working or not enabled

前端 未结 5 1234
后悔当初
后悔当初 2021-02-02 05:56

I have installed rewrite_module and modified php.ini on Apache.

I create rewrite.php and .htaccess files, but it\'s not working.

相关标签:
5条回答
  • 2021-02-02 06:43

    To get mod_rewrite to work for me in Apache 2.4, I had to add the "Require all granted" line below.

    <Directory /var/www>
       # Required if running apache > 2.4
       Require all granted
    
       RewriteEngine on 
       RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
     </Directory>
    

    supposedly a similar requirement exists for Apache 2.2 as well, if you're using that:

    <Directory /var/www>
       # Required if running apache 2.2
       Order allow,deny
       Allow from all
    
       RewriteEngine on 
       RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
     </Directory>
    

    Note that an ErrorDocument 404 directive can sometimes override these things as well, so if it's not working try commenting out your ErrorDocument directive and see if it works. The above example can be used to ensure a site isn't served from cache by including a subfolder in the path, though the files reside at the root of the server.

    0 讨论(0)
  • 2021-02-02 06:46

    Try setting: "AllowOverride All".

    0 讨论(0)
  • 2021-02-02 06:47

    Please try

    sudo a2enmod rewrite
    

    or use correct apache restart command

    sudo /etc/init.d/apache2 restart 
    
    0 讨论(0)
  • 2021-02-02 06:51

    On centOS7 I changed the file /etc/httpd/conf/httpd.conf

    from AllowOverride None to AllowOverride All

    0 讨论(0)
  • 2021-02-02 07:00

    It's working.

    my solution is:

    1.create a test.conf into /etc/httpd/conf.d/test.conf

    2.wrote some rule, like:

    <Directory "/var/www/html/test">
    RewriteEngine On
    RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
    </Directory>
    

    3.restart your Apache server.

    4.try again yourself.

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