Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-06-2011, 02:20 PM   PM User | #1
css-quest
New Coder

 
Join Date: Nov 2010
Posts: 45
Thanks: 7
Thanked 0 Times in 0 Posts
css-quest is an unknown quantity at this point
.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!
css-quest is offline   Reply With Quote
Old 04-06-2011, 05:35 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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]
?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 04-07-2011, 10:35 AM   PM User | #3
css-quest
New Coder

 
Join Date: Nov 2010
Posts: 45
Thanks: 7
Thanked 0 Times in 0 Posts
css-quest is an unknown quantity at this point
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 10:40 AM..
css-quest is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43 PM.


Advertisement
Log in to turn off these ads.