Forum Moderators: phranque
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]
# 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]
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