Forum Moderators: coopster
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...
[edited by: jatar_k at 11:58 pm (utc) on Mar. 27, 2004]
[edit reason] linked up url [/edit]
// .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...
Try this:
RewriteEngine on
RewriteCond %{REQUEST_URI}!^.*/index\.php$
RewriteRule (.*) index.php?page=$1 [L]
Seems to work on my server.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@___.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Apache/1.3.29 Server at www.___.com Port 80
The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.--------------------------------------------------------------------------------
HTTP 400 - Bad Request
Internet Explorer
sorry, but what code do i add to allow it to automatically go to the index
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
P.S. you can make it so the scripts don't filter spaces using the [ pre ] style code