1

I am attempting to mask an URL using an htaccess file to only show the root URL. This is a Drupal 7 website, so I want the URLs to look like the following:

Main page:
  http://www.site1.com
Drupal content:
  http://www.site1.com/content/....

There is also a test site that should appear as:

Test site:
  http://www.site1.com/site1-test
Test content:
  http://www.site1.com/site1-test/content/...

The directory structure is as follows:

 public_html/
            |--site1/
            |--site1-test/

Here is the htaccess file I've been working on in public_html/.htaccess. It mainly works, however there is a small issue. When I visit site1.com the URL appears as I want, however whenever I click any content it shows site1.com/site1/... instead of hiding the extra subdirectory. This is based on a prior StackOverflow question.

public_html/.htaccess

Options +FollowSymLinks
RewriteEngine on
#========================================================================
# FIRST Handle the http requests first before removing the additional url junk
#========================================================================
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1/$1

RewriteCond %{HTTP_HOST} ^(www.)?site1.com/site1-test$
RewriteCond %{REQUEST_URI} !^/site1-test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1-test/$1

#==========================================================
# SECOND Remove the additional url junk once the new url is loaded
#==========================================================
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1/index.php

RewriteCond %{HTTP_HOST} ^(www.)?rg$
RewriteRule ^(/)?$ site1/index.php

Previously I'd updated the $base_url variable in the settings.php file, however that seemed to break my themes unless if I pointed it directly to site1.com/site1, rather than to site1. At present, there is no defined $base_url.

  • "whenever I click any content it shows site1.com/site1/... instead of hiding the extra subdirectory" - Presumably your HTML links reflect your desired URL structure? – MrWhite Apr 2 '15 at 14:39
  • They currently do, yes. Though to be fair, the links are auto-generated by Drupal. – the_e Apr 2 '15 at 15:10
  • That would seem to suggest that something else (maybe Drupal?) is redirecting? Just to clarify, the link is showing site1.com/content, but the URL in the address shows site1.com/site1/content? If you check the network traffic, you presumably see the redirection? – MrWhite Apr 2 '15 at 15:15
  • The link is also showing site1.com/site1/content, and the URL reflects that. Updating $base_url in Drupal causes the link to show the appropriate content, however that breaks the Drupal theme. – the_e Apr 2 '15 at 15:18
  • "The link is also showing site1.com/site1/content" - That's what I was asking in the first comment. If the link is showing the undesirable URL then that needs to be fixed first (in Drupal). (Otherwise you would need to set up external redirects in .htaccess as well.) If the Drupal theme breaks when you change the URL then that would seem to be a "problem" with the theme? When you say "break", are you referring to the CSS? – MrWhite Apr 2 '15 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.