htaccess redirect query

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

littlemissgAsked:
Who is Participating?
 
abolinhasCommented:
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
 
jeremycrussellCommented:
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
 
littlemissgAuthor Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jeremycrussellCommented:
Are the images under the /moodle directory?
0
 
jeremycrussellCommented:
Also, may need to tune that RewriteCond a bit.

RewriteCond %{REQUEST_URI} !^/moodle.*
0
 
littlemissgAuthor Commented:
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
 
littlemissgAuthor Commented:
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
 
jeremycrussellCommented:
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
 
abolinhasCommented:
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
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
you have the .htaccess inside the moodle folder?
0
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
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
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
ok, try move the .htaccess to moodle/lib
0
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
I  access to your website and I was redirected to http://kcfe.ie/home/
0
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
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
 
littlemissgAuthor Commented:
Hi thats great thanks, do you know how I can amend the root htaccess to redirect the www also ?
0
 
abolinhasCommented:
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
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
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
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
Ok, try this
RewriteEngine On
RewriteRule ^(.*)$ home/$1 [L]

Open in new window

0
 
littlemissgAuthor Commented:
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
 
abolinhasCommented:
Try this
redirect 301 /home/ http://www.kcfe.ie/
redirect 301 /home/ http://kcfe.ie/
0
 
littlemissgAuthor Commented:
as well as previous code in htaccess or instead of ?
0
 
abolinhasCommented:
In htaccess replace the previous redirect code for this
redirect 301 /home/ http://www.kcfe.ie/
redirect 301 /home/ http://kcfe.ie/
0
 
littlemissgAuthor Commented:
Ok, tried this, site fails to load
0
 
abolinhasCommented:
Hi littlemissg

Any news?

Best resgards

André Bolinhas
0
 
littlemissgAuthor Commented:
So sorry I forgot to come back to this question until now ! thanks for all the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.