Link to home
Create AccountLog in
Avatar of littlemissg
littlemissgFlag for Ireland

asked on

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

Avatar of jeremycrussell
jeremycrussell
Flag of United States of America image

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...
Avatar of littlemissg

ASKER

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

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

RewriteCond %{REQUEST_URI} !^/moodle.*
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 ?
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 !

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.
Avatar of abolinhas
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

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
you have the .htaccess inside the moodle folder?
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 ?
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
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
ok, try move the .htaccess to moodle/lib
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]
I  access to your website and I was redirected to http://kcfe.ie/home/
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
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
Hi thats great thanks, do you know how I can amend the root htaccess to redirect the www also ?
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

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/

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]
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 !
Ok, try this
RewriteEngine On
RewriteRule ^(.*)$ home/$1 [L]

Open in new window

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.

Try this
redirect 301 /home/ http://www.kcfe.ie/
redirect 301 /home/ http://kcfe.ie/
as well as previous code in htaccess or instead of ?
In htaccess replace the previous redirect code for this
redirect 301 /home/ http://www.kcfe.ie/
redirect 301 /home/ http://kcfe.ie/
Ok, tried this, site fails to load
ASKER CERTIFIED SOLUTION
Avatar of abolinhas
abolinhas
Flag of Portugal image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi littlemissg

Any news?

Best resgards

André Bolinhas
So sorry I forgot to come back to this question until now ! thanks for all the help