I have been trying to do a htaccess URL rewrite (R=302) for a website which uses a $_get function to pull the content pages by use of strings. For instance, I am trying to change the following:
http://www.site.com/index.php?page=about
Into this:
However, I have managed to get it set up to the point where it will redirect the header and footer data within the index.php file if I use query the second URL, but it will not grab the CSS or the $_get information for the content. Here are the htaccess entries and the $_get information:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*?)/$ /index.php?page=$1 [NC,QSA,L]
RewriteRule ^(.*?)/$ $1.html [NC,L,QSA,R=302]
<?php
$folder = '';
$ext = 'html';
if (!$_GET['page'] || strpos($_GET['page'], '/') === true)
$path = 'home.' . $ext;
else $path = $_GET['page'] . '.' . $ext;
if (!file_exists($path)) {
$messages = array(
'404: Page does not exist; Please check the URL you entered.',
'404: Error 404, please check the URL of the page.'
);
print $messages[ rand(0, (count($messages) - 1)) ];
}
elseif (!@include($path)) print '300: couldn\'t get the page';
?>
Any help would be appreciated. I have been trying to modify the php code unsuccessfully thinking that is the issue.
First off, your two rewrite rules have the same condition, so only the first one will ever be met. I think you probably only want to rewrite if the requested uri doesn't exist on the server.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ /index.php?x=$1 [L]