[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

htaccess redirect problem

Our website was recently re-designed, and we replaced the homepage (index.html) with a new file (index.php). To ensure that links to the old home page are redirected to the new file, we included a 301 redirect from /index.html to /index.php. Works great.

Then, we added a subdomain for our mobile site. The subdomain mobile.oursite.com points to www.oursite.com/mobile. The homepage for the mobile site is mobile.oursite.com/index.html (or oursite.com/mobile/index.html).

The problem is that whenever someone goes to the subdomain, the htaccess file in the root of the site is apparently redirecting /mobile/index.html to the root of our site - so end users trying to access the mobile site are going to the main website instead.

How can I either change the root htaccess file to be more specific and avoid this problem - or add an htaccess file to the /mobile directory to override the rule in the root?
0
slovisa
Asked:
slovisa
  • 4
  • 3
  • 3
3 Solutions
 
giltjrCommented:
Is this a *nix OS?  If so, why not just create a symbolic link for index.html that points to index.php?

If you really want to use rewrite then you need to have a RewriteCond for /mobile and or hostname mobile.oursite.com.
0
 
slovisaAuthor Commented:
Yes, Linux. I'm using a 301 to permanently move index.html to index.php.

I'm not familiar with symbolic links or RewriteCond. Which way would be better, and where can I find more info about how to implement?

Thanks for the help.
0
 
giltjrCommented:
A symbolic link is basically a directory entry that "points" index.html to index.php.  This way no rewrites need to be done.  You can do:

    man ls

to see how to setup a link.  The RewriteCond you can go to:

     http://httpd.apache.org/docs/2.2/misc/rewriteguide.html

You would need to have a couple of conditions to check for mobile.oursite.com and www.oursite.com/mobile.

I personally would go with the symbolic link.   The only thing you might have to do is setup Apache so it will will call PHP for .html files.

You may need to add:

AddType application/x-httpd-php .htm .html
Addhandler application/x-httpd-php .html .php


To your Apache conf file.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

just to make this complete:

if you want to solve it with redirect, you could use some condition like the following for separation of urls:

RewriteEngine on
RewriteCond %{HTTP_HOST}        !^mobile\.domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/index.html
RewriteRule ^(.*)               http://www.domain.com/ [L,R=301]


this could be useful, if you want to avoid generating duplicate content (some search-engines rate sites with duplicate content lower)
0
 
Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

or if you prefer a solution without rewriteEngine:

first step:
enable parsing of .html-files with php as giltjr said:
"The only thing you might have to do is setup Apache so it will will call PHP for .html files.

You may need to add:

AddType application/x-httpd-php .htm .html
Addhandler application/x-httpd-php .html .php "


second step:
create a NEW index.html-File (no symlink!) with the following content:

<?php
 header ("Location: http://www.domain.com/");
 header ("HTTP/1.0 301 Moved Permanently");
?>



this will redirect users if they request "index.html" - so you avoid creation of duplicate content, but you do not have the complexibility of the RewriteEngine
0
 
slovisaAuthor Commented:
I'm still not totally clear on what I should do or why, but I feel all the options have been laid out here for me to evaluate.
0
 
Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

I would recommend the third solution - it combines the best things of answer one and two: you do not need complex rewrite rules, but you will get a clear 301-redirect for browser and search-engines to avoid double content, rated lower on search engines
0
 
slovisaAuthor Commented:
But won't the HTML redirect to PHP prevent people from seeing the index.html on the mobile site? Or is that only if HTML is not available?
0
 
giltjrCommented:
Oh, you really have index.html on the mobile site?  I thought you replaced index.html with index.php on both.

After thinking about it the easiest way to do this is no rewrite and no symbolic link.  Change your DirectoryIndex parameter  The defauult is:


     DirectoryIndex index.html

Change it to:

     DirectoryIndex index.php index.html

What this will do is look for index.php first, if it exist it will serve that up, if it does not exist, it will look for index.html and serve that up.

So in your mobile directory you should have have a index.html, but no index.php.  

In your non-mobile directory you will have a index.php, but no index.html.  

0
 
slovisaAuthor Commented:
Nice! Thanks!
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now