Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache mod_rewrite is not working or not enabled

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

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

My filesystem folders like:

/var/www/html /var/www/html/test /var/www/html/test/.htaccess /var/www/html/test/rewrite.php 

/var/www/html/.htaccess content is:

$ cat /var/www/html/test/.htaccess   RewriteEngine On  RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L] 

/var/www/html/rewrite.php

$ cat /var/www/html/test/rewrite.php   <html> <h2 align=center>  <?php  // mod_rewrite Test Page  // Copyright 2006 Webune.com  if($_GET['link']==1){echo"You are not using mod_rewrite";}  elseif($_GET['link']==2){echo"Congratulations!! You are using Apache mod_rewrite";}  else{echo"Linux Apache mod_rewrte Test Tutorial";}  ?>  </h2>  <hr>  <head>  <title>How To Test mod_rewrite in Apache Linux Server</title>  </head>  <body>  <p align="center">by <a href="http://www.webune.com">Webune</a></p>  <p><a href="rewrite.php?link=1">LINK1</a> = rewrite.php?link=1</p> <p><a href="link2.html">LINK2</a> = link2.html</p>  <p>How this works: both links are for this same page, except they both are different. link one is without the mod_rewrite and link2 is using mod_rewrite. Link1 show the php file, with with mod_rewrite we are mascarading the php file into a html file. you can use whatever type of extension you want, you can change it to .htm or .shtml etc... all you have to do is to make sure you also chang it in the .htaccess file</p>  <p>&lt;&lt; <a href="http://www.webune.com/forums/viewtopic-p-62.html">Go back to webune forums.</a></p>  </body>  </html> 

mod_rewrite.so is installed.

$ ls -l mod_rewrite.so -rwxr-xr-x 1 root root 59256 Sep 20 23:34 mod_rewrite.so 

rewrite_module is loaded.

$ cat /etc/httpd/conf/httpd.conf | grep mod_rewrite.so LoadModule rewrite_module modules/mod_rewrite.so 

AllowOverride setting

$ cat /etc/httpd/conf/httpd.conf <Directory "/var/www/html">     Options Indexes FollowSymLinks      AllowOverride None      Order allow,deny     Allow from all </Directory> 
like image 575
rc1021 Avatar asked Oct 19 '11 04:10

rc1021


People also ask

How do you check mod_rewrite is enabled or not?

In PHP, there is an inbuilt function called 'phpinfo'. By using this function, we can output all the Loaded Modules and see the 'mod_rewrite' is enabled or not. Syntax: phpinfo();

How do I enable Apache mod rewrite?

Step 1 — Enabling mod_rewrite In order for Apache to understand rewrite rules, we first need to activate mod_rewrite . It's already installed, but it's disabled on a default Apache installation. Use the a2enmod command to enable the module: sudo a2enmod rewrite.


2 Answers

Try setting: "AllowOverride All".

like image 130
Jarrod Avatar answered Sep 27 '22 17:09

Jarrod


Please try

sudo a2enmod rewrite 

or use correct apache restart command

sudo /etc/init.d/apache2 restart  
like image 41
ASHOK Avatar answered Sep 27 '22 17:09

ASHOK