views:

248

answers:

1

I've followed some tutorials on how to use Mod_Rewrite, but it's not working out.

I have a php index page that takes a page parameter like so:

call: index?page=name1, name2, name3 etc.

<?php

if (isset($_GET['page']))
{
    switch($_GET['page'])
    {
       case 'front':
       include "front.php";
       break;

       default:
       break;
       }
}

?>

I'd like to run mod-rewrite so that the urls display as site.com/name1. Is this possible with the code i'm using above?

Below is what I've been trying in the apache config files to no avail.

apache/conf/http.conf

line 122: LoadModule rewrite_module modules/mod_rewrite.so
line 188: DocumentRoot "G:/xampp/htdocs"
line 198: #default
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

line 215:  <Directory "G:/xampp/htdocs">
line 228:  Options Indexes FollowSymLinks Includes ExecCGI
line 235:  AllowOverride All

# cgi
line 355:
<Directory "G:/xampp/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory> 

G:\xampp\apache\conf\extra\http.v-hosts.conf

<VirtualHost *:80>
DocumentRoot G:/xampp/htdocs/
ServerName localhost
ServerAdmin admin@localhost

<Directory "G:/xampp/htdocs/localhost/">
Options Indexes FollowSymLinks
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost> 

<VirtualHost *:80>
DocumentRoot G:/xampp/htdocs/site2/
ServerName site2.localhost
ServerAdmin [email protected]

<Directory "G:/xampp/htdocs/site2.localhost/">
Options Indexes FollowSymLinks
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

.htaccess file

IndexIgnore *

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
A: 

mod_rewrite can only rewrite/redirect requests. So you actually have to use /foobar to the outside and request /foobar to have mod_rewrite rewrite it internally to /index.php?page=foobar. That’s a common misconception people have about how mod_rewrite works.

Gumbo
So Gumbo if you type site.com/foobar, or link it into the url, mod_rewrite would call /index.php?page=foobar internally, and site.com/foobar is all you would see in the url? Any advice on how to achieve my original goal without mod_rewrite then? Perhaps through php?
rrrfusco
@rrrfusco; Well, simply link to `/foobar` instead of `/index.php?page=foobar`.
Gumbo