htaccess: Redirect all pages including subdomain to index.

Please support our RSS, Web Services and SOAP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2005
Posts: 102
Reputation: martinkorner is an unknown quantity at this point 
Solved Threads: 0
martinkorner's Avatar
martinkorner martinkorner is offline Offline
Junior Poster

htaccess: Redirect all pages including subdomain to index.

 
0
  #1
Sep 17th, 2009
Hi,

I am trying to write a .htaccess script that can redirect any URL on my site (whether it exists or not, including sub-domains) to the index page of that site.

For example:
example.com/pages/page.htm ---> example.com
sub.example.com/page.htm ---> example.com
error.example.com/error ---> example.com

I've tried a few things with mod_rewrite but I can't seem to get existing urls, non-existing urls and sub domain urls to all direct to the index page.

Thanks,
Martin
Last edited by martinkorner; Sep 17th, 2009 at 2:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 62
Reputation: kylegetson is an unknown quantity at this point 
Solved Threads: 9
kylegetson's Avatar
kylegetson kylegetson is offline Offline
Junior Poster in Training

Re: htaccess: Redirect all pages including subdomain to index.

 
1
  #2
Sep 19th, 2009
Originally Posted by martinkorner View Post
Hi,

I am trying to write a .htaccess script that can redirect any URL on my site (whether it exists or not, including sub-domains) to the index page of that site.

For example:
example.com/pages/page.htm ---> example.com
sub.example.com/page.htm ---> example.com
error.example.com/error ---> example.com

I've tried a few things with mod_rewrite but I can't seem to get existing urls, non-existing urls and sub domain urls to all direct to the index page.

Thanks,
Martin

try this:
RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. RewriteEngine On
  2. RewriteCond %{REQUEST_URI} !=/index.php
  3. RewriteRule .* /index.php
try changing index.php to index.html, or whatever the index file is you want to see. i think that will work, though I havnt tested it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 102
Reputation: martinkorner is an unknown quantity at this point 
Solved Threads: 0
martinkorner's Avatar
martinkorner martinkorner is offline Offline
Junior Poster
 
0
  #3
Oct 7th, 2009
Thanks Kyle,

Sorry for the delayed reply.

That worked perfectly

Thanks again,
Martin
Reply With Quote Quick reply to this message  
Reply

Tags
.htaccess, 301, htaccess, redirect

Message:



Similar Threads
Other Threads in the RSS, Web Services and SOAP Forum


Views: 2187 | Replies: 2
Thread Tools Search this Thread



Tag cloud for .htaccess, 301, htaccess, redirect
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC