?
Solved

Apache: Load special index page if no get or post queries

Posted on 2011-04-21
9
Medium Priority
?
241 Views
Last Modified: 2012-05-11
If my site is hit without any post or get queries, I want 'home.html' to be loaded.

For example, if someone goes here:
http://www.example.com/

This page should be loaded:
http://www.example.com/page.html

But if they go here:
http://www.example.com/?a=1

Then the normal index file should be loaded.
0
Comment
Question by:hankknight
  • 6
  • 3
9 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35444473
Try this in your apache configuration.


<IfModule mod_rewrite.c>
 RewriteEngine on
RewriteCond %{HTTP_HOST} example.com/*$
RewriteRule (.*) http://www.example.com/page.html [R=301,L]
</IfModule>
0
 
LVL 16

Author Comment

by:hankknight
ID: 35446946
I do not want to redirect.  I want the content of "page.html" to be loaded if there is no post or get query.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35447004
Ok, then try this:

Locate the

DirectoryIndex index.html ....

Entry in your apache config file (httpd.conf or apache.conf) and modify it to look like

DirectoryIndex page.html ...

Just include page.html in the list of files.  Make sure in your DirectoryRoot, there is no other file (e.g. index.html) included in the DirectoryIndex list.

Would this solution work for you?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Author Comment

by:hankknight
ID: 35447091
I do NOT want page.html to be the directory index if there is a get or a post query.

For example:

http://www.example.com/
Should return page.html as the index file

http://www.example.com/?abc=1
Should NOT return page.html as the index file

A form submitted to http://www.example.com/
Should NOT return page.html as the index file
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35447118
Ok, I understand this one although I did not understand your objection with the first solution that I gave you.  It would have done exactly what you wanted.
0
 
LVL 31

Accepted Solution

by:
farzanj earned 2000 total points
ID: 35447509
Here is another solution for you.
<IfModule mod_rewrite.c>
 RewriteEngine on
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_METHOD} !=GET
RewriteCond %{HTTP_HOST} example.com
RewriteRule .*  /page.html
</IfModule>

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 35447510
The problem with the first solution is that it redirects.  It sends a 301 redirection header.  I want it to send the content of the page but not redirect.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35447538
And the last solution?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35447542
Yes, in the first one we could simply get rid of those flags as I did in the third one.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question