Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

htaccess and mod_rewrite problem

Featured Replies

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

  • 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 ??

  • 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');

?>

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

  • 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 by lstables

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?

  • 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?

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

either remove index from the url or alter your htaccess rewrite to have index at the beginning (before home)

Edited by ChristopherDarling

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.