Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

htaccess redirect query

Posted on 2011-02-15
32
Medium Priority
?
779 Views
Last Modified: 2012-05-11
I have a domain which I redirect to a subdirectory e.g. /home and I use htaccess to redirect it with 301 etc all fine.
Problem is there is now another subsystem (moodle install) in another subdirectory e.g. /moodle

Although the address http://www.example.com/moodle loads, it is not correct when htaccess is inplace, as in the images and css don't load correctly.

I would like to add code to existing htaccess to prevent the example.com/moodle directory from being redirected.but few options I have tried failed

I will paste my current htaccess code below
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ /home [L,R=301]

Open in new window

0
Comment
Question by:littlemissg
[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
  • 15
  • 13
  • 4
32 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 34896705
Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{REQUEST_URI} !^/moodle
RewriteRule ^$ /home [L,R=301]


I removed "RewriteRule (.*) http://www.example.com/$1 [R=301,L]" because it's kind of redundant.  This rule is just grabing the URI and then putting it back...
0
 

Author Comment

by:littlemissg
ID: 34896817
Hi Jeremy
Thanks for that, unfortunately its the same result
The root domain redirects fine and the moodle site loads however without image files or login functionality

0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 34897093
Are the images under the /moodle directory?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:jeremycrussell
ID: 34897125
Also, may need to tune that RewriteCond a bit.

RewriteCond %{REQUEST_URI} !^/moodle.*
0
 

Author Comment

by:littlemissg
ID: 34897137
Hi,
Yes they are all part of a moodle theme which are in subdirectories of moodle directory as is css.

I could just go change syle paths etc but the fact that I cannot login either in moodle when use the htaccess makes it seem like more than just images are affected ?
0
 

Author Comment

by:littlemissg
ID: 34897194
Hi sorry just saw your second post,
That different condition, allowed moodle directory to work perfetly, however the root directory failed to load anything just hung the browser !

0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 34897717
Do you happen to be using firefox?  If so.... get a plugin called httpfox, start it up and hit your site and post the output.

The other alternative would be to move moodle under /home.
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34905452
Try this:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} moodle 
RewriteRule ^(.*)$ http://www.example.com/moodle/$1 [R,L]

Open in new window

0
 

Author Comment

by:littlemissg
ID: 34906901
Hi Abolinhas,
Thanks however the moodle site fails to load at all with this code in htaccess and it doesn't address the issue of redirecting the root to /home

Thanks anyway
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34906931
you have the .htaccess inside the moodle folder?
0
 

Author Comment

by:littlemissg
ID: 34907263
Hi, I didn't!
Have tried it though and it doesn't load at all, do I need to change the text in the root htaccess ?
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34907362
Hi,

Don't put this code inside the .htaccess of you root

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} moodle
RewriteRule ^(.*)$ http://www.example.com/moodle/$1 [R,L]

delete if you add

If you have a .htaccess inside moodle folder add the code, if not, create a new .htaccess and paste the code
0
 

Author Comment

by:littlemissg
ID: 34907580
Hi, yes that is what I did, I put your code in a .htaccess and put  that into moodle folder, the moodle site wouln't load.
My Q was do I need to alter the original htaccess that was already in root from allowing root redirect to home, which is (from previous advice on this thread) :

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{REQUEST_URI} !^/moodle.*
RewriteRule ^$ /home [L,R=301]

I tried removing the moodle condition from this file, but moodle still failed and I removed the .htaccess from root completely and moodle still failed to load with the code you gave me in the .htaccess in the moodle folder
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34908127
ok, try move the .htaccess to moodle/lib
0
 

Author Comment

by:littlemissg
ID: 34908352
Hi,
Ok the moodle site works fine now, however the root site doesnt redirect to /home anymore

this is the .htaccess of the root curently


RewriteEngine on
RewriteCond %{HTTP_HOST} ^kcfe\.ie$
RewriteCond %{REQUEST_URI} !^/moodle.*
RewriteRule ^$ /home [L,R=301]
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34908563
I  access to your website and I was redirected to http://kcfe.ie/home/
0
 

Author Comment

by:littlemissg
ID: 34908907
I have a http redirect function in an index file in the root at the moment as a band aid until the .htacess works, you will see it flash up for a second before directs you on
Or else my routers  cache here is not seeing updated htaccess
I will look at this from another internet connection tonight
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34909247
if I access by http://kcfe.ie I don't get any php redirect (seems that htaccess is working).

if I access by www.kcfe.ie I get a php redirect
0
 

Author Comment

by:littlemissg
ID: 34912185
Hi thats great thanks, do you know how I can amend the root htaccess to redirect the www also ?
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34912282
try this
Options +FollowSymLinks
RewriteEngine on

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?kcfe.ie$
RewriteRule ^(/)?$ home/ [R=301,L]

RewriteCond %{HTTP_HOST} ^kcfe\.ie$
RewriteRule ^(/)?$ home/ [R=301,L]

Open in new window

0
 

Author Comment

by:littlemissg
ID: 34917196
Hi, sorry for late reply.
Thanks but that additional condition had a strange effect on appending the linux path to the url
http://kcfe.ie/var/www/vhosts/kcfe.ie/httpdocs/home/

0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34917223
Sorry I don't understand you comment :(

You mean that this code don't work ?
Options +FollowSymLinks
RewriteEngine on

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?kcfe.ie$
RewriteRule ^(/)?$ home/ [R=301,L]

RewriteCond %{HTTP_HOST} ^kcfe\.ie$
RewriteRule ^(/)?$ home/ [R=301,L]
0
 

Author Comment

by:littlemissg
ID: 34917464
Hi, sorry I didn't explain properly when I use that code in the htaccess in the root

http://kcfe.ie gets routed to :

http://kcfe.ie/var/www/vhosts/kcfe.ie/httpdocs/home/

and http://www.kcfe.ie gets routed to:

http://www.kcfe.ie/var/www/vhosts/kcfe.ie/httpdocs/home/

which is the apache server path of the files appended on to the url !
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34917548
Ok, try this
RewriteEngine On
RewriteRule ^(.*)$ home/$1 [L]

Open in new window

0
 

Author Comment

by:littlemissg
ID: 34917722
Hi,
Site fails to load with those lines in, just gives :

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34917822
Try this
redirect 301 /home/ http://www.kcfe.ie/
redirect 301 /home/ http://kcfe.ie/
0
 

Author Comment

by:littlemissg
ID: 34917910
as well as previous code in htaccess or instead of ?
0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34918069
In htaccess replace the previous redirect code for this
redirect 301 /home/ http://www.kcfe.ie/
redirect 301 /home/ http://kcfe.ie/
0
 

Author Comment

by:littlemissg
ID: 34918450
Ok, tried this, site fails to load
0
 
LVL 9

Accepted Solution

by:
abolinhas earned 1000 total points
ID: 34918668
hum...I belive that you don't have the mod_rewrite enable in your apache.

You have two option.

1º - Try enable the mod_rewrite in your apache.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

2º - More easy, create a index.php in root (/) and add the this code
<?php
header( 'Location: http://www.kcfe.ie/home' ) ;
?> 

Open in new window

0
 
LVL 9

Expert Comment

by:abolinhas
ID: 34939780
Hi littlemissg

Any news?

Best resgards

André Bolinhas
0
 

Author Comment

by:littlemissg
ID: 35702651
So sorry I forgot to come back to this question until now ! thanks for all the help
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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