2011-10-19 44 views
37

He instalado rewrite_module y modificado php.ini en Apache.Apache mod_rewrite no está funcionando o no está habilitado

Creo archivos rewrite.php y .htaccess, pero no está funcionando.

Mis carpetas del sistema de archivos como:

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

contenido /var/www/html/.htaccess es:

$ 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 está instalado.

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

rewrite_module cargado.

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

AllowOverride establecer

$ cat /etc/httpd/conf/httpd.conf 
<Directory "/var/www/html"> 
    Options Indexes FollowSymLinks 

    AllowOverride None 

    Order allow,deny 
    Allow from all 
</Directory> 

Respuesta

5

Inténtelo

sudo a2enmod rewrite 

o uso correcto del comando de reinicio de Apache

sudo /etc/init.d/apache2 restart 
+0

pero no tengo comando 'a2enmod'. porque, mi dispositivo es [yum install apache] – easter1021

+0

¿Qué sistema operativo está utilizando? (CentOS, Ubuntu, etc.) – ASHOK

+1

Mi sistema operativo es "AWS EC2 t1.micro". lo siento, ocupado más tarde. – easter1021

4

Está funcionando.

mi solución es:

1.Create un test.conf en /etc/httpd/conf.d/test.conf

2.wrote alguna regla, como:

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

3. reinicie su servidor Apache.

4.traiga nuevamente usted mismo.

+3

Es bueno que haya encontrado una solución, pero no termine su respuesta con otra pregunta. – slugster

+0

Tenga en cuenta que si coloca estas directivas en httpd.conf en lugar de .htaccess, se requiere la etiqueta de directorio. – Aaron

0

Para que mod_rewrite funcione para mí en Apache 2.4, tuve que agregar la línea "Requerir todo otorgado" a continuación.

<Directory /var/www> 
    # Required if running apache > 2.4 
    Require all granted 

    RewriteEngine on 
    RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
</Directory> 

supuestamente existe un requisito similar para Apache 2.2, así, si usted está utilizando lo siguiente:

<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> 

Tenga en cuenta que una directiva ErrorDocument 404 veces puede anular estas cosas así, por lo que si no está funcionando intente comentar su directiva ErrorDocument y vea si funciona. El ejemplo anterior se puede usar para garantizar que un sitio no se sirva desde la memoria caché al incluir una subcarpeta en la ruta, aunque los archivos residen en la raíz del servidor.

0

En centOS7 I cambiado el archivo /etc/httpd/conf/httpd.conf

de AllowOverride None a AllowOverride All

Cuestiones relacionadas