Solved

htaccess redirect query

Posted on 2011-02-15
32
772 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
  • 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
 
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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 250 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

12 Experts available now in Live!

Get 1:1 Help Now