Forum Moderators: phranque

Message Too Old, No Replies

.htaccess not working

i can't redirect my pages to a vitrual domain

         

apache_ocj

12:58 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Hi all,

i'm newbie in apache stuff so my doubt is very simple and common.

I have a link like test.php?s=sports.

I want it to become domain_name/sports.

I've already created an .htaccess file with the following code:

RewriteEngine On
RewriteRule ^(A-Za-z)$ /test.php?s=$1

and the test.php is:
<?php

$menu = array('home','sports','fashion','news');

for($i = 0; $i < 5; $i++)
{
echo '<ul>';

echo '<a href="'.$menu[$i].'">';
echo '<li>'.$menu[$i];
echo '</a>';

echo '</ul>';
}

$s = $HTTP_GET_VARS['s'];
echo $s; //when the page is reloaded by clicking on menu it'll show the name of the item choosen.

?>

Everything seems right but it's not working. Can anyone help me cause my project is stoped by this problem.

By the way, i,m running all this locally so the real url would be [localhost...] and the virtual [localhost...]

Thanks

DMCunningham

3:10 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



By the way, I'm running all this locally so the real url would be [localhost...] and the virtual [localhost...]

Well I don't know how to get it to run as “http://localhost/sports” but if you wanted something like:

[localhost...]

I can help out with that.

“go” is the filename of the php script that does the parsing of "varname" (and in this example that would be “sports”). To make this work you will need to make a symlink from "go" to a file with a .php extension. First you will need to “cd” into the directory where the extensionless file would go and created the link:


$ cd /home/example/htdocs

$ ln -s go go.php

Then use mod_rewrite to pass all requests for the URL invisibly to the go.php script by putting these rewrite rules in an .htaccess file in the same directory or above this directory:

RewriteEngine on
RewriteCond %{REQUEST_URI}!go\.php
RewriteRule ^go(.*)$ /go.php$1

apache_ocj

11:37 am on Jun 22, 2005 (gmt 0)

10+ Year Member



Hi,

i have one question about your suggestion regarding the non working of htaccess file on my case.

Where should i put the code
$ cd /home/example/htdocs
$ ln -s go go.php

By the way i'm testing on W2K OS and my directory structure is very simple - D:\localhost\. So every file used in the test - .htaccess and test.php - is under this directory.

One more thing, should i make any particular configuration on Apache Server? I've just enabled two lines from the default httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

Thanks

ocj