Welcome to WebmasterWorld Guest from 54.234.114.182

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Cleaning up just the homepage URL

Changing from HTML to PHP

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 23, 2003
posts:801
votes: 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]

4:22 am on June 20, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 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

6:36 am on June 20, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 23, 2003
posts:801
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members