0

Thanks in advance, I am trying to redirect anyone who types in example.com or example.com/index.php to example.com/home

Please let me know, I have tried the htaccess rules of redirect permanent and 301's and they have not worked. My pages are created dynamically.

4sha
  • 326
  • 1
  • 3
  • 12
KGDD
  • 99
  • 2
  • 10

2 Answers2

1

First, make sure your syntax is correct. Is this what your .htaccess file looked like?

Redirect 301 / http://example.com/home
Redirect 301 /index.php http://example.com/home

If you're sure, try this:

RewriteEngine on
RewriteBase /
RewriteRule ^& http://example.com/home [L,R=301] 
RewriteRule index.php http://example.com/home [L,R=301]
4sha
  • 326
  • 1
  • 3
  • 12
Nick Q.
  • 3,947
  • 2
  • 23
  • 37
  • Is it possible to make it a "one-time" redirect where when the user types in the address bar 'www.mysite.com' or 'mysite.com' the 'mysite.com/home' page is loaded instead? I have pages created dynamically that go off of the index.php template (i.e. the php code on the index page pulls in the mysql data to populate and use the index.php as the template) So everytime I do the above code, no matter what link I click on, it brings me back to 'www.mysite.com/home'. Thoughts? – KGDD Oct 24 '11 at 12:59
  • I thought there might be something screwy with my fist `RewriteRule`, try this: `RewriteRule / http://mysite.com/home [L,R=301]` – Nick Q. Oct 24 '11 at 14:03
0

Couldn't you just put a php script to redirect visitors? The following should work, save it as index.php in your root directory.

<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.yoursite.com/home" ); 
?> 
Whetstone
  • 1,199
  • 8
  • 8
  • Is it possible to make it a "one-time" redirect where when the user types in the address bar 'www.mysite.com' or 'mysite.com' the 'mysite.com/home' page is loaded instead? I have pages created dynamically that go off of the index.php template (i.e. the php code on the index page pulls in the mysql data to populate and use the index.php as the template) So everytime I do the above code, no matter what link I click on, it brings me back to 'www.mysite.com/home'. Thoughts? – KGDD Oct 24 '11 at 12:59
  • www.mysite.com and mysite.com should be handled through DNS settings AFAIK, so that's irrelevant. Forgive me if I'm wrong, but are you saying that you use index.php as a script to help build pages? It seems to be that there has to be a better solution to this - it's kind of like building a factory and putting the machinery in the reception. Couldn't you use a separate page to house that script? If you're insistent, you could always pass a variable to index.php that flags the call as internal, and do the following... if($flag){ //Use page for site building } else { //redirect } – Whetstone Oct 24 '11 at 13:25