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

Edited by martinkorner: n/a

5
Contributors
5
Replies
27
Views
7 Years
Discussion Span
Last Post by guruparthi
1

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.

0

Thanks Kyle,

Sorry for the delayed reply.

That worked perfectly :)

Thanks again,
Martin

0

This worked for me:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ index.php/$1 [QSA,L]
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.