April 1, 201115 yr Hi all, I have a problem, mod_rewrite/.htaccess not working for some reason and not sure why. I have this in my htaccess file RewriteEngine On RewriteRule ^page/([^/]*)\.html$ /?page=$1 [L] my pages are all php and looking like - index.php?page=mypage Any help advice would be very much appreciate been at this 45 mins and still no joy. Thanks Lee
April 1, 201115 yr Author When this is sorted will I also need to change my links from index.php?page=mypage to the new url like index/page/home ??
April 1, 201115 yr Author Forgot to mention i also have this index.php page <?php //ini_set('display_errors', true); include_once('func/cart.php'); session_start(); // Databse Connection File require ('inc/db.php'); // Include Header & Meta include ('inc/header.php'); include ('inc/meta.php'); //Specify Base URL // Url and Show page switch($_GET['page']) { case "checkout": <-// Will this need to be changed to reflect the htacess file? include('checkout.php'); break; case "about": include('about.php'); break; case "contact": include('contact.php'); break; case "help": include('help.php'); break; default: include('home.php'); } // Include Footer include ('inc/footer.php'); ?>
April 1, 201115 yr Looking at it quickly it should be rewriting page/home to ?page=home Hi all, I have a problem, mod_rewrite/.htaccess not working for some reason and not sure why. I have this in my htaccess file RewriteEngine On RewriteRule ^page/([^/]*)\.html$ /?page=$1 [L] my pages are all php and looking like - index.php?page=mypage Any help advice would be very much appreciate been at this 45 mins and still no joy. Thanks Lee
April 1, 201115 yr Author Hi Chris, Yes it does re-write ?page=home to page/home, but what do i need to to the links in the nav and the case in index.php? Edited April 1, 201115 yr by lstables
April 1, 201115 yr Hi Chris, Yes it does re-write ?page=home to page/home, but what do i need to to the links in the nav and the case in index.php? I don't really understand what you're meaning. Any links on your site should now be using the page/home format. Not index.php?page=home. Does that answer your question?
April 1, 201115 yr Author I don't really understand what you're meaning. Any links on your site should now be using the page/home format. Not index.php?page=home. Does that answer your question? Thanks chris yes my links are as below: <li><a href="index/page/products/" title="">Home</a></li> <li><a href="index/page/specials/" title="">Specials</a></li> <li><a href="index/page/otherproducts/" title="Other Products">Other Products</a></li> <li><a href="index/page/about/" title="About Us">About Us</a></li> <li><a href="index/page/contact/" title="Contact Us">Contact</a></li> <li><a href="index/page/help/" title="Help">Help</a></li> But when these link they do like and show up in the url has http://localhost/index/page/products/ but they aren't showing the content from the sql database becasue of the switch case i Have in index.php switch($_GET['page']) { case "home": include('home.php'); break; } So do i need to change the case to index/page/home too so that it reconises the URL?
April 1, 201115 yr The following: RewriteEngine On RewriteRule ^(.*)/ /index.php?page=$1 [L] Will convert /home/ to /index.php?page=home It only works if the trailing slash is present in the URL, e.g. /home/ not /home... Therefore you need a 404 error document to redirect when the trailing slash is missing. - ionix
April 1, 201115 yr either remove index from the url or alter your htaccess rewrite to have index at the beginning (before home) Edited April 1, 201115 yr by ChristopherDarling
April 1, 201115 yr Author Thanks guys but sorted it by copying my wordpress htaccess so posting it here for future reference if anyone else has the same problem SetEnv DEFAULT_PHP_VERSION 5 Options +FollowSymLinks RewriteEngine on # 301 Redirect all requests that don't contain a dot or trailing slash to # include a trailing slash # except for form POSTS RewriteCond %{REQUEST_URI} !/$ RewriteCond %{REQUEST_URI} !\. RewriteCond %{REQUEST_METHOD} !POST$ RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L] # Rewrites urls in the form of /parent/child/ # but only rewrites if the requested URL is not a file or directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ index.php?page=$1 [QSA]
Create an account or sign in to comment