Solved

.htaccess - Hiding the subdirectory using wordpress

Posted on 2014-03-27
7
524 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
  • 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 50

Accepted Solution

by:
Steve Bink earned 333 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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 167 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 50

Assisted Solution

by:Steve Bink
Steve Bink earned 333 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now