Forum Moderators: phranque
RewriteEngine on
RewriteRule ^([0-9a-zA-z]*)\.php$ foo.php [L] RewriteCond $1 !^foo.php$ before the RewriteRule to fix this. ^([0-9a-zA-z]*)\.php$ allows a URL request for example.com/.php to be valid. The * should be changed to + to prevent that happening. example.com/<anything>.php and fetch the content from the file at foo.php. The address bar will continue to show the originally requested URL.
This code is an internal rewrite. It will accept a URL request for example.com/<anything>.php and fetch the content from the file at foo.php. The address bar will continue to show the originally requested URL.
example.com/short and for an internal rewrite to connect that request to a /much-longer-path/and-file-name.php inside the server.
<a href="http://mysite.com/?i=2">Click Here</a> <?php
switch ($i) {
case 0:
include page1.htm;
case 1:
include page2.htm;
case 2:
include page3.htm;
}
?>
/index.php and calling it with parameters like /index.php?p=234 displays the various pages, there is no need for the /index.php or the ?p=234 part to appear in the URL in *that* form. example.com/p234 and then also re-arranging the rewrite code so that the rewrite internally calls the script at /index.php?page=234 without revealing that location to the outside world. DirectoryIndex index.php
RewriteEngine On
# Rewrite URL request for example.com/p<num> to script at /index.php?page=<num>
RewriteRule ^p([0-9]+)$ /index.php?page=$1 [L] .htaccess code examples right here in this forum. <?php
switch ($i) {
case 0:
include page1.htm;
case 1:
include page2.htm;
case 2:
include page3.htm;
}
?> Then figure out the .htaccess to make a "pretty" url.
DirectoryIndex index.php
RewriteEngine On
# Rewrite URL request for example.com/p<num> to script at /index.php?page=<num>
RewriteRule ^([A-Za-z0-9]+)$ /index.php?i=$1 [L] <?php
$var = strip_tags($_GET['i']);
if (file_exists("$var.php"))
{
include "$var.php";
}Else{
include '0.php';
}
?> It looks good so far. I assume 0.php includes:
<?php HEADER "HTTP/1.1 404 Not Found"; ?>
or similar.
I don't see how the code supplies a page for "example.com/" requests. That is when "i" is blank. You'll need to test for that.
I suggest that you not ignore even the tiniest suggestion that's been posted...
What did I miss?
So, you send the index page when "i" is blank, the correct numbered page if it exists, and the 404 HEADER and error message when a page does not exist.
<!DOCTYPE ....>
<html>
<head><title>Page Not Found</title></head>
<body>Error. Page Not Found.</body>
</html>