954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

htaccess: Redirect all pages including subdomain to index.

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

martinkorner
Junior Poster
102 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

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:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.php
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.

kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
 

Thanks Kyle,

Sorry for the delayed reply.

That worked perfectly :)

Thanks again,
Martin

martinkorner
Junior Poster
102 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: