Forum Moderators: coopster
<?php
// Sanatize the request and put its parts into an array called $url_array
$url_request = strip_tags($_SERVER['REQUEST_URI']);
$url_array = explode("/", $url_request);
// Clean $url_array by removing empty elements
// The first element is always empty so let's shift it off
array_shift($url_array);
// If the last element is also empty then pop it off
if(end($url_array) == ""){
array_pop($url_array);
}
// if $url_array is empty, show home and exit this script
if (empty($url_array)){
include("home.html");
exit();
}
$filename = implode("-", $url_array) . ".html";
if ( file_exists($filename) ) {
// file exists, include it
include($filename);
exit();
} else {
// file does not exist, should return a 404
// header('HTTP/1.0 404 Not Found');
exit("<h1>404 Not Found</h1>\nThe page that you have requested could not be found. You may like to start over from <a href='/'>Home</a>");
}
?>
Options -MultiViews
ErrorDocument 404 /404.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
<a href="/therapy/acupunture">Accupunture</a> throughout the site? ^([^/.]+)$ for root or ^(([^/]+/)+[^/.]+)$ for folders, or similar. Yes, there's now two rules.
Options -MultiViews
ErrorDocument 404 /404.html
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
RewriteRule ^([^/.]+)$ /index.php
RewriteRule ^(([^/]+/)+[^/.]+)$ /index.php [L]
header('HTTP/1.0 404 Not Found') commented out. The reason for that is that it was giving me a warning that it couldn't do it. I'm not at my work computer so I can't reproduce the error right now for a better explanation.
<?php
// Report all PHP errors
error_reporting(E_ALL);
// Show what's running
// echo $_SERVER['PHP_SELF'] . "<br>";
// Sanatize the request and put its parts into an array called $url_array
$url_request = strip_tags($_SERVER['REQUEST_URI']);
$url_array = explode("/", $url_request);
// Clean $url_array by removing empty elements
// The first element is always empty so let's shift it off
array_shift($url_array);
// If the last element is also empty then pop it off
if(end($url_array) == ""){
array_pop($url_array);
}
// If $url_array is empty, show home and exit this script
if (empty($url_array)){
include("home.html");
exit();
}
// Create the file name to include
$filename = implode("-", $url_array) . ".html";
// Try to include the file, if fails then return 404
if ( !include($filename) ){
//header('HTTP/1.0 404 Not Found');
exit("404 <a href='/'>Home</a>");
}
?>
# Necessary for 1&1 - http://httpd.apache.org/docs/2.0/content-negotiation.html
Options -MultiViews
# Tell Apache to enable mod_rewrite
RewriteEngine On
# Redirect non-www requests to www
# RewriteCond %{HTTP_HOST} !^www\.
# RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([^/.]+)$ /index.php [L]
RewriteRule ^(([^/]+/)+[^/./?]+)$ /index.php [L]
ErrorDocument 404 /404.html
# 1&1 supported:
#
# ErrorDocumentDefine your own error pages.
# AddTypeAssign a MIME-Type to a file ending.
# RewriteEngineActivate mod_rewrite module
# Allow/DenyHost or IP based access control
# FilesMatchFile based access control
# AuthType"Basic" password check
# RedirectRedirection to another page or site
# Options(de)activate index, symbolic links, etc.
[edited by: g1smd at 1:09 pm (utc) on Feb 17, 2012]