...

View Full Version : .htaccess files



css-quest
04-06-2011, 03:20 PM
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 (http://www.webweaver.nu/html-tips/web-redirection.shtml).

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.


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.

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!

abduraooft
04-06-2011, 06:35 PM
but it only adds www. to the Homepage index.php file in public_html and does not recurse into my subdirectories. How about

RewriteCond %{HTTP_HOST} ^yoursite.com$ [NC] ?

css-quest
04-07-2011, 11:35 AM
but it only adds www. to the Homepage index.php file in public_html and does not recurse into my subdirectories. How about

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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum