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 3 of 3

Thread: .htaccess files

  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    49
    Thanks
    7
    Thanked 0 Times in 0 Posts

    .htaccess files

    Hi there. I have been working with my .htaccess file lately following the launch of a newly designed website, redirecting old pages to new and implementing custom 404/500 error pages. However, the next step I want to tackle is one I read here.

    Firstly, is I want all non-www pages to be redirected to www. pages (to avoid search engine content duplication). I have implemented the following script (as shown in the tutorial) into my .htaccess file, but it only adds www. to the Homepage index.php file in public_html and does not recurse into my subdirectories.

    Code:
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC] 
    RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
    --------
    The second issue I want to tackle is redirecting /folder/index.php to /folder. I have tried the script on the same website that is recommended for doing this (as below), but then every time I click on my "Home" links in my website (as in the HTML, I have linked my Home button to (../../)index.php), it thinks the directory file for the homepage is then www.mywebsite.com/public_html instead of just www.mywebsite.com and consequently results in a "403 Forbidden" error message.
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    # index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
    Obviously the public_html folder is the default directory, but I don't understand why it's behaving this way and not just showing the domain without any following directory!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    but it only adds www. to the Homepage index.php file in public_html and does not recurse into my subdirectories. How about
    Code:
    RewriteCond %{HTTP_HOST} ^yoursite.com$ [NC]
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    49
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    but it only adds www. to the Homepage index.php file in public_html and does not recurse into my subdirectories. How about
    Code:
    RewriteCond %{HTTP_HOST} ^yoursite.com$ [NC]
    ?
    That works but then it adds "www.mysite.com/index.php" to the URI. Also when I click other links on the page it removes the "www." when landing on those other pages; even though they
    are linked with www.

    Edit: I've got it to work but now when I click any links from within a page such as www.mysite.com/mypage it will instead go to www.mysite.com/public_html/mypage, which doesn't exist...! My .htaccess file is in the directory above public_html as this is how the webhost has set it up. I don't know if that makes a difference?
    Last edited by css-quest; 04-07-2011 at 11:40 AM.


  •  

    Posting Permissions

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