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!