homepage Welcome to WebmasterWorld Guest from 54.205.106.111
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Cleaning up just the homepage URL
Changing from HTML to PHP
DerekH




msg:3372379
 5:21 pm on Jun 19, 2007 (gmt 0)

I'm a bit embarrassed to come here cap-in-hand with a very simple query but I can't find it spelled out clearly enough for me to risk it on my home page...

I'm on a virtual server and can't see the httpd.conf, but I can write my own .htaccess

When my home page was url/index.html, it could be reached by url/ and that was what stayed in the address bar, courtesy, I guess of the httpd.conf

I changed just that one homepage to PHP last week. I know some websites have linked to me including the index.html, so I put a redirect on url/index.html to url/index.php using htaccess.

So far so good!

Now, by whatever means someone addresses my site (with or without either type of index file), the address bar always has index.php on the end. I guess it goes from url to url/index.html to url/index.php

I'd like to get rid of the index.php from the address bar, just for this one page, only using htaccess and without going recursive (as happened on my one experiment!)

Has someone got an example I can copy?
TIA....
DerekH

[edited by: DerekH at 5:23 pm (utc) on June 19, 2007]

 

jdMorgan




msg:3373071
 4:22 am on Jun 20, 2007 (gmt 0)

This replaces any/all of your rules pertaining to your home page:

# Externally redirect direct client requests for "index.html" or "index.php" to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html¦php)
RewriteRule ^index\.(html¦php)$ http://www.example.com/ [R=301,L]
#
# Internally rewrite requests for "index.html" or "/" to "index.php"
RewriteRule ^(index\.html)?$ /index.php [L]

THE_REQUEST is the entire request header sent by the client. It is never updated as the result of any internal operation, and therefore can be used to differentiate between externally-requested and internally-rewritten URLs, and thereby avoid redirect/rewrite looping.

In order to understand the regex in the RewriteCond, it may help to look at a typical value for THE_REQUEST:
GET /index.php?cc=uk&lang=en HTTP/1.1

The server may internally rewrite requests for "/" to "index.html" as a result of (I assume) a DirectoryIndex directive set in httpd.conf, either by your host or by your use of a "control panel". So, the second rule looks for either "/" or "/index.html" requests (in the top-level directory only), and sends those to your new PHP home page.

Replace all broken pipe "¦" characters in the code above with solid pipes before use; Posting on this forum modifies the pipe characters.

Jim

DerekH




msg:3373144
 6:36 am on Jun 20, 2007 (gmt 0)

Thank you Jim
I'll make a pot of tea and try that straight away :-)
DerekH

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved