Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts

    HTACCESS problem - loop error

    Hey guys

    Im stuck with a problem...i'll explain the issue.

    I published my website and the path was something like www.example.com/example.php and it was indexed by google. I have now redone my directories so the path is now www.example.com/uk/example.php

    So when a visitor goes to example.com it should go to example.com/uk/
    As google has already indexed the old path, im assuming I need a 301 redirect to phase out the old path and introduce the new path...correct me if im wrong?

    Ive tried the following basic 301 redirect...but it returns a 'indefinate loop'.

    Code:
     Redirect 301 / http://www.example.com/uk/

    Please someone let me know what im doing wrong...ive spent hours searching and found nothing!

    Thanks!

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    try this;

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://www.domain.com/dir/$1 [R=301,L]

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Thanks for that...

    I tried it and for some reason the page doesnt seem to be loading correctly. I went to www.webpagetest.org and tested the website.

    Basically i have a subdomain (ie. images.example.com which is located at example.com/images). The htaccess seems to be causing the website to load whatever is in the subdomain twice (ie. once from images.example.com and again from example.com/images).

    Any ideas to how to fix this?

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    Can you update whats the error you are getting to help you better.

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Theres no actual error. Heres whats happening:

    Scripts are located at 'http://script.example.com/script.js' whose actual path is 'http://www.example.com/script/script.js'.

    According to webtestpage.org, 'http://script.example.com/script.js' is being loaded aswell as 'http://www.example.com/uk/script/script.js', the latter doesnt exist.

    So i assume the htaccess above rewrites all urls under example.com to example.com/uk/. That is why when the page loads it doesnt look/behave correctly.

    So what I suppose I need is to force (if possible) the htaccess file to just work in the root and not in the subdirectories? Is this possible? Or is there anything else I can do...maybe force the script directory to always reference the subdomain??

    Hope this is clear, let me know if it isnt. Thanks!
    Last edited by vorl; 01-15-2010 at 04:33 PM.

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Update:

    I found some code on the net which excludes sub domains from the rewriterule:

    Code:
    RewriteCond %{HTTP_HOST} ^scripts\.example\.com
    RewriteRule .* – [L]
    However now when I test it on webtestpage it gives me a '500' error for the files located on the subdomain!

    What is going on here? Anyone know who to resolve this? Please....

  • #7
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Solved! For anyone interested, I missed a line of code (RewriteBase /) out.

    Heres what I eventually used:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^script\.example\.com
    RewriteRule .* - [L]
    
    RewriteCond %{HTTP_HOST} !^(.*)\.example\.com/uk/$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/uk/$1 [R=301,L]
    Thanks!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •