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.
site1.com/content
, but the URL in the address showssite1.com/site1/content
? If you check the network traffic, you presumably see the redirection?$base_url
in Drupal causes the link to show the appropriate content, however that breaks the Drupal theme.