Page 1 of 1
HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 9:29 am
by simonmlewis
Code: Select all
RewriteEngine On
RewriteRule ^/$ index.php?page=home&menu=home[L]
Hi.
I am trying to get the htaccess to work for the first time - I've never done this before. Am reading all about it, but frankly I only need it for the homepage. ie.
http://www.domain.co.uk/
That needs to go to the full index.php...... url.
How do I use my rewrite code to do this??
Simon
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 10:16 am
by pickle
If possible, this is something you should set up in the Apache config files. I think there's a directive for default page, or directory index, or something along those lines. If you can't change the config files, you should be able to use those exact same directives in your .htaccess file. You don't need mod_rewrite for this.
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 10:17 am
by jackpf
You mean like this?
Code: Select all
RewriteEngine On
RewriteRule ^$ index.php?page=home&menu=home [L]
EDIT
Pickle, didn't see you there. Probably better option tbh. Yeah, there should be a directoryindex directive, where you can specify several pages, which will be tried for existence in order.
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 10:23 am
by simonmlewis
Perfect!!!
I did try it by faking the index.html page, but it refused to show the &menu=home
God knows why, coz ur's works.
Brilliant. Thanks.
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 10:27 am
by jackpf
Well, I removed the forward slash from the regex, since it's not considered part of the location apparently...
I also put a space between the filename you're using to handle the request and "[L]".
Code: Select all
index.php?page=home&menu=home[L] #will show $_GET['menu'] as 'home[L]', and apache will not process it
index.php?page=home&menu=home [L] #correct

Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 11:31 am
by simonmlewis
Code: Select all
RewriteRule ^$ index.php?page=home&menu=home&head=welcome [L]
This fails too for another site - and I have the space...??
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 11:34 am
by jackpf
Have you got
in there anywhere?
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 11:47 am
by simonmlewis
Yes.
It's just that line that's wrong somehow.
Code: Select all
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^$ index.php?page=home&menu=home&head=welcome [L]
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 12:44 pm
by jackpf
Works for me. Is that the whole htaccess file? Are htaccess files even enabled on the server?
Visiting just
http://localhost/ , I get
Code: Select all
Array ( [page] => home [menu] => home [head] => welcome )
when I

Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 1:13 pm
by simonmlewis
No, this is the entire file
Code: Select all
DirectoryIndex index.htm index.html index.php
order allow,deny
deny from 81.144.190.133
allow from all
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^$ index.php?page=home&menu=home&head=welcome [L]
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 2:58 pm
by jackpf
It works for me. As I said, are you sure you have htaccess files enabled on that server?
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 3:03 pm
by simonmlewis
Yes - it's been checked.
Without the mod-rewrite bit, it's fine.
Re: HTACCESS Mod-rewrite - how do you do it just for homepage?
Posted: Mon Sep 21, 2009 3:07 pm
by jackpf
I'm clueless then :/
Since it works for me, I can't really start to debug it since...well, it works
Sorry.