htaccess redirection

They have: 1 posts

Joined: Jul 2011

I have a domain, eg dom.com, with various sub-domains, eg sub.dom.com. I would like to change the homepage of dom.com from index.html to index.php. To achieve this I added the line "redirect 301 /index.html http://dom.com/index.php" to .htaccess. Although this works for the main domain it also redirects the homepages of the subdomains to dom.com/index.php. How can I restrict the re-direct to the root directory of the top domain and leave sub-domains and sub-directories untouched?

DavidIpswich's picture

He has: 117 posts

Joined: Aug 2009

What software are you using to build your site?

If you've got both index.html and index.php you can simply just delete the index.html page.

The search engine will look for index.html and when it doesn't find it it'll then look for the alternatives and find index.php

They have: 17 posts

Joined: Aug 2011

Hi Friend,
for error page we do not use any software we simply use this code and simply paste it on server.

<?php
get_header
();
?>

Error 404 - Not Found

<?php
get_sidebar
();
?>

<?php
get_footer
();
?>

They have: 3 posts

Joined: Oct 2011

In what way does the redirect fail? What actually happens?

Where in the .htaccess file is the code positioned?

Where in the server filesystem is the .htaccess file placed?

{links removed}

They have: 25 posts

Joined: Oct 2012

Hello,

You can put the following code in .htaccess file to pull up the website using index.php

DirectoryIndex index.php index.html

The first on the list should be index.php. You can add others to the list as well like index.htm, home.htm, default.htm.

But keep in mind by default your server pulls index.html first and you want to use this method to pull index.php first in the event that both files exist in a directory, this acts recursively. So for the sub-domains you have to create .htaccess file for sub-domain separately and revert the changes back, if you want sub-domain to access using index.html page you will need to put following code in .htaccess file

DirectoryIndex index.html index.php

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.