I need someone who knows .htaccess rules and maybe global redirect, who help me fix an issue on a live site. I'm hoping someone knowledgeable might know the solution, or figure it out in under an hour, in the ball park of $20-$40. I'll give access to the files and site and be available on the phone or irc during the work.

#1001022: /node/N not redirecting to /content/alias for main domain on host monster when code is in public_html/live subdirectory

Comments

yesct’s picture

I'm upping the price to $100, and also will try and find a regular person I could work with. I build sites, but sometimes need someone who knows more than me to help me out when I get stuck.

yesct’s picture

yesct’s picture

Hosting is currently on hostmonster. It's a upgrade to their pro hosting package, so it has a dedicated ip and security certificate.

the main host is in a subdirectory, and in order to get that to work with hostmonster I had to put a .htaccess in the public_html main directory.

The instructions for getting the live site in a subdirectory from hostmonster were:

Problem:

    How do I make a sub directory (or sub folder) act as the public_html for your main domain? 

Solution:

    The main domain on the hosting account uses the public_html directory for all of its Web site files. Addon domains use sub directories inside the public_html directory. In order to also set up your main domain to use a subdirectory on your hosting account you will need to set up a redirect in the .htaccess file in the public_html folder so that the server knows that any request for your main domain will be redirected to a subdirectory on public_html.

    To setup the rewrite/redirect, edit the ~/public_html/.htaccess file. Insert the following code block and make modifications as noted in the (#) comments.

    # Hostmonster.com
    # .htaccess main domain to subdirectory redirect
    # Copy and paste the following code into the .htaccess file
    # in the public_html folder of your hosting account
    # make the changes to the file according to the instructions.
    # Do not change this line.
    RewriteEngine on
    # Change yourdomain.com to be your main domain.
    RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteCond %{REQUEST_URI} !^/subdirectory/
    # Don't change this line.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteRule ^(.*)$ /subdirectory/$1
    # Change yourdomain.com to be your main domain again.
    # Change 'subdirectory' to be the directory you will use for your main domain
    # followed by / then the main file for your site, index.php, index.html, etc.
    RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
    RewriteRule ^(/)?$ subdirectory/index.php [L]


    Visitors to your Web site will not be able to tell that your main domain is using a subdirectory, they will still see the Web site address as http://www.yourdomain.com/page.html. 

public_html .htaccess

The actual file in public_html is (replaced my domain with myexampleusa):

code tags didnt work, so using pre tag
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php

# Hostmonster.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?myexampleusa.org$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/live/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /live/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?myexampleusa.org$
RewriteRule ^(/)?$ live/index.php [L]

public_html/live/.htaccess

But have more changes to .htaccess files than just that, as I also want to use https for all traffic.
In the live directory the .htaccess file is

code tags didnt work, so using pre tag
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.

  Order allow,deny


# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.

  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found."


# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.

  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0


# PHP 4, Apache 2.

  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0


# PHP 5, Apache 1 and 2.

  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0


# Requires mod_expires to be enabled.

  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  


# Various rewrite rules.

  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
   RewriteCond %{HTTP_HOST} ^www\.myexampleusa\.org$ [NC]
   RewriteRule ^(.*)$ http://myexampleusa.org/$1 [L,R=301]
# trying to make whatever/live go to whatever -cewt
#   RewriteCond %{HTTP_HOST} ^myexampleusa\.org\/live$ [NC]
#   RewriteRule ^(.*)$ http://myexampleusa.org/$1 [L,R=301]

# http://crackingdrupal.com/blog/greggles/drupal-and-ssl-multiple-recipes-possible-solutions-https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
   RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


# $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $
yesct’s picture

I also have some settings in the sites/default/settings.php that might effect things.

base url in settings.php

/**
 * Base URL (optional).
 *
 * If you are experiencing issues with different site domains,
 * uncomment the Base URL statement below (remove the leading hash sign)
 * and fill in the absolute URL to your Drupal installation.
 *
 * You might also want to force users to use a given domain.
 * See the .htaccess file for more information.
 *
 * Examples:
 *   $base_url = 'http://www.example.com';
 *   $base_url = 'http://www.example.com:8888';
 *   $base_url = 'http://www.example.com/drupal';
 *   $base_url = 'https://www.example.com:8888/drupal';
 *
 * It is not allowed to have a trailing slash; Drupal will add it
 * for you.
 */
 $base_url = 'https://myexampleusa.org';  // NO trailing slash!
yesct’s picture

I was hoping I had the rules in the wrong order or something simple...

yesct’s picture

I'm not sure, hostmonster support suggested it might maybe have to do with my "permalink settings in the .htaccess file"

Roberto Gerola’s picture

Hello.
Perhaps a simpler solution would be to rename the main directory public_html to something else, like public_html_files and then make a symbolic link public_html pointing to the subdirectory.

Could this work for you ?

Roberto Gerola’s picture

to comment the line:
RewriteBase / in your .htaccess file.

I think you should be sure your website work correctly when called as : http://mywebsite.com/live/
and then fix the redirects, from my point of view.