EnexoOnoma
EnexoOnoma

Reputation: 8836

RewriteRule is not working on all servers because of configuration?

In a folder named rewrite I have two files, .htaccess and index.php

<rewrite>
- .htaccess
- index.php

In .htaccess I have this content

RewriteEngine On
RewriteRule ^([a-z0-9]+)?$ index.php?id=$1 [NC,L]

and in index.php

<?php
echo $_GET['id'];
?>

Isn't supposed when I visit www.domain.com/rewrite/1234 I would get an output of 1234 ?
Instead of this there is created a file application/x-httpd-php for downloading that contains the code of index.php

I am trying to figure out why I can not make this happen. What am I missing here?

UPDATE
I have tested two web servers and local server. Finally it worked on one of the web servers, meaning that it has something to do with the configurations.

What should I do about it ?

Upvotes: 1

Views: 121

Answers (1)

Galled
Galled

Reputation: 4206

Is possible that one of your servers hasn't got the mod_rewrite activated.

To ensure make a test:

In a folder make two files: - .htaccess - rewrite.php

In .htacces put:

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

and in rewrite.php put:

<h2 align=center>
<?
if(isset($_GET['link']))
{
    if($_GET['link']==1){echo "Link without use mod_rewrite";}
    elseif($_GET['link']==2){echo "Congratulations!! You has used Apache's mod_rewrite and works well.";}
    else{ echo "Verify the Apache's module mod_rewrite.";}
}
?>
</h2>
<hr>
<head>
<title>Test mod_rewrite in Apache Linux</title>
</head>
<body>
<h1>Test mod_rewrite in Apache Linux</h1>
<p><a href="rewrite.php?link=1">Link one </a> = rewrite.php?link=1</p>
<p><a href="link2.html">Link two</a> = link2.html</p>
<ul>
<li>Test link one</li>
<li>Then test the link two</li>
<li>If with the link two if the link two goes to a not found page then you have not activated the .htaccess or apache mod_rewrite is not working.</li>
</ul>
</body>
</html>

Upvotes: 1

Related Questions