?
Solved

.htaccess - Hiding the subdirectory using wordpress

Posted on 2014-03-27
7
Medium Priority
?
544 Views
Last Modified: 2014-03-31
Currently we have the following configuration on our .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /v2/index.php [L]
</IfModule>

# END WordPress

RewriteCond %{HTTP_HOST} ^meadeauto\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadeauto\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com\/v2" [R=301,L]
RewriteCond %{HTTP_HOST} ^meadegroup\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadegroup\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^meadelexus\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadelexus\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com" [R=301,L]

Open in new window


When you visit www.meadeauto.com it shows www.meadeauto.com/v2 in the browser URL bar. We want it to show (rewrite): www.meadeauto.com in the URL bar.

We have tried various combinations, including this solution we found on a blog post:

RewriteBase /

# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.yoursite.com/$1/ [R=301,L]

#Change http://yoursite.com to http://www.yoursite.com (Optional)
RewriteCond %{HTTP_HOST} ^yoursite.com$
RewriteRule ^/?(.*)$ http://www.yoursite.com/$1 [R=301,L]
#Rewrites http://www.yoursite.com/subdir to http://www.yoursite.com/
RewriteCond %{REQUEST_URI} !^/subdir
RewriteRule ^(.*)$ subdir/$1 [L]

Open in new window


That seemed to change it to meadeauto.com in the url bar, but also broke www.gistroy.com (another domain, which is in the /gis/ folder on our main directory).
0
Comment
Question by:meade470
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:eemit
ID: 39960998
Insert this above the line:
# BEGIN WordPress

# protect "dir"
Options All -Indexes

Open in new window

0
 
LVL 2

Author Comment

by:meade470
ID: 39961321
eemit, unfortunately that is still showing the subdirectory (www.meadeauto.com/v2/) when loading meadeauto after making the change to:

# protect "dir"
Options All -Indexes

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /v2/index.php [L]
</IfModule>

# END WordPress

RewriteCond %{HTTP_HOST} ^meadeauto\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadeauto\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com\/v2" [R=301,L]
RewriteCond %{HTTP_HOST} ^meadegroup\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadegroup\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^meadelexus\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadelexus\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com" [R=301,L]

Open in new window

0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 1332 total points
ID: 39961353
Your first RewriteRule set after the WordPress section is explicitly commanding the redirect you want to avoid.   Because you are also using that set to enforce a canonical domain, it must necessarily be a redirect, not a simple rewrite.   You'll need to separate those concepts:
RewriteCond %{HTTP_HOST} ^meadeauto\.com$ [NC]
RewriteRule ^/?(.*)$ http://www.meadeauto.com/$1 [R=301,L,QSA]
RewriteRule ^/?$ /v2 [L]

Open in new window


The second issue is your report of rewrites bleeding over to other domains.  This is due to directing more than one domain to the same document root.  If you cannot properly separate the domains, then all of your rewrites must be modified to include a check for the domain.  The above set would be modified to:
RewriteCond %{HTTP_HOST} ^meadeauto\.com$ [NC]
RewriteRule ^/?(.*)$ http://www.meadeauto.com/$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^www\.meadeauto\.com$ [NC]
RewriteRule ^/?$ /v2 [L]

Open in new window

Ideally, separate the domains to have more granular control with less rewrite management.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 2

Author Comment

by:meade470
ID: 39961872
routinet, thanks for the thorough response. We changed it to the following:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /v2/index.php [L]
</IfModule>

# END WordPress

RewriteCond %{HTTP_HOST} ^meadeauto\.com$ [NC]
RewriteRule ^/?(.*)$ http://www.meadeauto.com/$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^www\.meadeauto\.com$ [NC]
RewriteRule ^/?$ /v2 [L]
RewriteCond %{HTTP_HOST} ^meadegroup\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadegroup\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^meadelexus\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.meadelexus\.com$
RewriteRule ^/?$ "http\:\/\/www\.meadeauto\.com" [R=301,L]

Open in new window


but unfortunately were still getting the same results. Do you have any further recommendations/changes?
0
 
LVL 2

Author Comment

by:meade470
ID: 39962036
We completely re-wrote it and it now contains:

# The below settings will forward each incoming domain name to the respective
# folders. gis/ is gistroy.com and v2/ is meadeauto.com WP install
# RewriteEngine On
# RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
# RewriteRule ^(/)?$ subdir/index.php [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?gistroy.com$
RewriteRule ^(/)?$ gis/index.php [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?meadeauto.com$
RewriteRule ^(/)?$ v2/index.php [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?meadelexus.com$
RewriteRule ^(/)?$ v2/index.php [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?meadegroup.com$
RewriteRule ^(/)?$ v2/index.php [L]

# Added the below to prevent htaccess viewing and directory listings

<Files .htaccess>
order allow,deny
deny from all
</Files>

Options All -Indexes

 

Open in new window


It seems to work now! We used this resource from WP for it.

Any additional suggestions to spruce it up is appreciated.
0
 
LVL 15

Assisted Solution

by:eemit
eemit earned 668 total points
ID: 39962225
Not sure, but check if you also need Non-www to www, 301 redirect:

# BEGIN Non-www to www
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^YourDomain.com
RewriteRule (.*) http://www.YourDomain.com/$1 [R=301,L]
# END Non-www to www

Open in new window

0
 
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 1332 total points
ID: 39962357
What you have now looks fine, though give consideration to eemit's comment regarding enforcing the canonical "www" domain.  

The complexity of your rewrites are necessary because of the combined document root.  Likewise, remember that any rewrite set you include will act on *all* domains pointing to that root.  In order to isolate behavior on just one of the sites, you will need to include the RewriteCond check for the host name before each RewriteRule.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question