Forum Moderators: phranque

Message Too Old, No Replies

htaccess to remove /home.html?

         

Phillyman

6:52 pm on Aug 29, 2012 (gmt 0)

10+ Year Member



How would I go about using the .htaccess file to remove the words "home.html" from my websites front page. I am using an Invision Power Board forum, and having it generate a homepage, but in order to generate the page....it must have a name. I could shorten it to www.example.com/home.......but I would worry about any other page that has the word home in it, getting rewritten.

Basically I have....

www.example.com/home.html

and I want

www.example.com

Any help is appreciated

Thanks
Robert

g1smd

6:58 pm on Aug 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rewrite requests for "/" to the filename that is used internally to serve the content.

That's a rewrite, not a redirect. Use a RewriteRule with the [L] flag.

Phillyman

7:03 pm on Aug 29, 2012 (gmt 0)

10+ Year Member



Sorry I am not sure I entirely understand. This is the current .htaccess that sits at www.example.com. Its required for generating the content pages that my forum software generates. Although I am at a loss as to how it actually accomplishes this.

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !.*\.(jpeg|jpg|gif|png|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Phillyman

7:07 pm on Aug 29, 2012 (gmt 0)

10+ Year Member



would I add

RewriteRule . /home.html [L]

right before the closing tags?

g1smd

7:15 pm on Aug 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not quite. The rule pattern will be ^$ or !. not . to match root requests.

The "root" rule must also be the first of the rewrites as it affects only one URL.

Phillyman

7:23 pm on Aug 29, 2012 (gmt 0)

10+ Year Member



How about?

RewriteRule ^(.*)$ /home.html/$1 [L]

g1smd

7:53 pm on Aug 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



(.*) isn't ^$ or !.

To match root requests, the rule pattern will be ^$ or !. and not . or (.*)

Phillyman

8:03 pm on Aug 29, 2012 (gmt 0)

10+ Year Member



I did that and it doesn't seem to really do anything....

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^$ /home.html [L]
RewriteCond %{REQUEST_FILENAME} !.*\.(jpeg|jpg|gif|png|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Its the first Rewrite Rule, and it has the ^$. I also tried it with and without the /$1 and with the !. with /$1 and without. Nothing seems to be changing.

Phillyman

8:24 pm on Aug 29, 2012 (gmt 0)

10+ Year Member



Nevermind, I found a way to omit the home.html from within the forum software. Thanks anyway for helping out.

lucy24

9:00 pm on Aug 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Edit: This was written before I saw the very last post.

Wait, wait. Before anything else. If you have no rules in place, what happens when you request

www.example.com/

by itself?

If you get taken to the home.html page, it means that mod_dir has already got "home.html" on its list of possible DirectoryIndex filenames. If so, all you have to do is redirect (not rewrite) any request for "home.html" to / alone. That's "request" as in {THE_REQUEST} coming from outside.

ElseIf you get taken to the index.html page, it means that mod_dir is looking for index.html -- and finding one, which is messy and complicated and will need sorting out. I personally know of a site that has both index.jsp and main.jsp; which one you get taken to depends on what it finds in your cookies and probably some other variable that I can't pinpoint. My own, uninformed, modest and humble opinion is that the programmer should be shot.

ElseIf you get a 403* page, it means that mod_dir is looking for index.html and not finding it. This is better than the preceding, because you only need to add "home.html" to the DirectoryIndex options. This can be done in htaccess.

Else ... actually, I don't think there is a final "Else". I just ran out of possibilities. Let us not contemplate a 500-class error round about here.


* I am on the verge of writing up some boilerplate about this, because people who are seriously into the www business forget that to an ordinary human, 403 does not mean "Get out of my sight, you horrible robot". It simply means "Sorry, you blundered into the wrong directory." And that's who the 403 page should be aimed at.

Phillyman

3:24 pm on Aug 30, 2012 (gmt 0)

10+ Year Member



In the past 8 years of running a website, the htaccess file is still my worst nightmare. If I am Batman, the .htaccess file is Bane (hell bent on destroying Gotham (my website). But at last, everything is right in the world and my site functions as intended. :)