Forum Moderators: phranque
I'm posting in PHP and Apache because it uses both techniques
i need a script that will redirect a .html to a?page=
examples:
site.com/pictures.html to site.com/index.php?page=pictures.html
site.com/this.php to site.com/index.php?page=this.php
i think it uses mod_rewrite but i've never used it before. does anyone have an appropriate script?
thank you in advance for any help...
RewriteEngine on
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteRule (.*) index.php?page=$1 [L]
Jim
// .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI}!^index\.php$
RewriteRule (.*) index.php?page=$1 [L]
// index.php
echo "this is the index<body bgcolor=black text=white><br>";
if ($page!= "") { include("$page"); }
// test.php
echo "this is test.php";
if i goto:
// server.com/folder
The page cannot be found
// server.com/folder/test.php
this is the index
this is the index
this is the index
this is the index
this is the index...
// server.com/folder/index.php
this is the index
this is the index
this is the index
this is the index
this is the index...
this code works perfect
except, it won't allow you to access the dir
/dir/index.php works but /dir/ returns a page not found message...any suggestions?
i was thinking about mabye adding a
RewriteCond %{REQUEST_URI}/$
RewriteRule (.*) index.php [L]
is this about right?
RewriteEngine on
RewriteCond %{REQUEST_URI}!^.*/index\.php$
RewriteRule (.*) index.php?page=$1 [L]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) index.php [L]
i also changed the include() function to include_once() to fix errors caused by accessing dir/index without the extention