.htaccess redirect subfolder to appear as main domain

Discuss practical ways rearrange URLs using mod_rewrite.

.htaccess redirect subfolder to appear as main domain

Postby dr_m » Tue Jul 29, 2008 5:06 am

I have a valid drupal installation in a subfolder of public_html at bluehost. I followed the instructions at http://helpdesk.bluehost.com/kb/index.p ... d=2&id=394 and have a modified version of the .htaccess file given there in my public_html directory. (pasted below) The default drupal .htaccess file is also in the drupal directory, also slightly modified with the relevant info. Everything works EXCEPT for my site's main page, index.php. When you navigate to just my main domain you get a page not found error. In order for the home page to show you have to manually add /drupal at the end of the url. All of the other pages work fine and the /drupal doesn't show, i.e. http://anthonymosakowski.com/compositions (which is what I want). I'm assuming it's the bottom two lines of code that aren't working, but I don't know anything about how to fix them. Any help? Thanks a lot.

****public_html htaccess****

# Bluehost.com
# .htaccess main domain to subfolder 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.)?anthonymosakowski.com$


# Change 'subfolder' to be the folder you will use for your main domain.

RewriteCond %{REQUEST_URI} !^/drupal/

# Don't change this line.

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

# Change 'subfolder' to be the folder you will use for your main domain.

RewriteRule ^(.*)$ /drupal/$1

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder 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.)?anthonymosakowski.com$
RewriteRule ^(/)?$ drupal/index.php [L]





******* drupal dir htaccess ********

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>

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

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Customized error messages.
ErrorDocument 404 /index.php

# 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.
<IfModule mod_php4.c>
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
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
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
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
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
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
# Do not cache dynamically generated pages.
ExpiresByType text/html A1
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
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\.anthonymosakowski\.com$ [NC]
RewriteRule ^(.*)$ http://anthonymosakowski.com/$1 [L,R=301]

# 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 old-style URLs of the form 'node.php?id=x'.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{QUERY_STRING} ^id=([^&]+)$
#RewriteRule node.php index.php?q=node/view/%1 [L]

# Rewrite old-style URLs of the form 'module.php?mod=x'.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
#RewriteRule module.php index.php?q=%1 [L]

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

# $Id: .htaccess,v 1.81.2.4 2008/01/22 09:01:39 drumm Exp $
dr_m
 
Posts: 3
Joined: Tue Jul 29, 2008 5:02 am

Postby richardk » Tue Jul 29, 2008 11:57 am

Try the following in /public_html/.htaccess
Code: Select all
Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?anthonymosakowski\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^drupal(/.*)?$ /drupal%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby dr_m » Tue Jul 29, 2008 3:46 pm

Thanks very much for the reply. Your code seems to be faster than the bluehost code, but ends up with the same results: everything is redirected except for the plain domain. I can only get to my front page if I manually add /drupal or /index.php after the main domain in the url. Any other ideas?
dr_m
 
Posts: 3
Joined: Tue Jul 29, 2008 5:02 am

Postby richardk » Wed Jul 30, 2008 3:47 pm

Doh, try
Code: Select all
Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?anthonymosakowski\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^drupal(/.*)?$ /drupal%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

no dice

Postby dr_m » Thu Jul 31, 2008 4:44 am

Thanks but no go. This did not work either. I realized in the course of testing this that I was having some browser caching issues, but after fixing that it looks like your revised code still gives the same results as the bluehost code. I did open a help ticket about this at bluehost, but they've been slow in responding. If you (or anyone) have any other ideas I'd greatly appreciate it. Thanks again.

Anthony
dr_m
 
Posts: 3
Joined: Tue Jul 29, 2008 5:02 am

Postby richardk » Fri Aug 01, 2008 3:46 pm

Try
Code: Select all
Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteRule ^$ /durpal/ [QSA,L]

RewriteCond %{HTTP_HOST} ^(www.)?anthonymosakowski\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^drupal(/.*)?$ /drupal%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 25 guests

cron