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 08-25-2012, 04:07 PM   PM User | #1
fine0023
New Coder

 
Join Date: Sep 2011
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
fine0023 is an unknown quantity at this point
htaccess code clarification

I have the following code in my htaccess (but with my actual domain name of course), and I'm not sure if I understand exactly what it is all for....I was just wondering if someone could help explain precisely what this means.

#if the domain is not www.mydomain.com
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
#redirect to www.mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]

#leave this rule in place, but after the one above to handle the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ http://www.mydomain.com/$1 [R=301,L]
fine0023 is offline   Reply With Quote
Old 08-28-2012, 03:29 PM   PM User | #2
handlegeek
New to the CF scene

 
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
handlegeek is an unknown quantity at this point
Quote:
#if the domain is not www.mydomain.com
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
#redirect to www.mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
This is for redirecting from non-www domain to www domain
Example:
Code:
mydomain.com -> www.mydomain.com
NC => no case comparison
R=301 => 301 redirect
L => Last condition[/CODE]

Quote:
#leave this rule in place, but after the one above to handle the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ http://www.mydomain.com/$1 [R=301,L]
This is to extract directory path (uppercase letters - length between 3 to 9 characters) for the URLs ending with index.html and redirect to directory path.
For example:
Code:
www.mydomain.com/TEST/index.html -> www.mydomain.com/TEST/
%{THE_REQUEST} => Request URI (Ex:TEST/index.html)

For more details: http://www.ganeshbabujayaraman.com/a...and-drupal-cms
handlegeek is offline   Reply With Quote
Old 09-03-2012, 10:46 AM   PM User | #3
fine0023
New Coder

 
Join Date: Sep 2011
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
fine0023 is an unknown quantity at this point
I was wondering if it is necessary to keep all of this code in my htaccess....because I have www.mydomain.com set as my hard canonical name, which I think is supposed to redirect aliases such as mydomain.com automatically (without having to code anything in htacess). However, I don't think this has anything to do with redirecting index.html to the non-index.html url. Would it make sense to take out the first part:
Code:
#if the domain is not www.mydomain.com
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
#redirect to www.mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
and leave in the second part:
Code:
#leave this rule in place, but after the one above to handle the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
RewriteRule ^(.*)index\.html$ http://www.mydomain.com/$1 [R=301,L]
?
fine0023 is offline   Reply With Quote
Old 09-07-2012, 06:14 PM   PM User | #4
mike333
New to the CF scene

 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mike333 is an unknown quantity at this point
Rewrite rules don't actually "hide" URLs, they just change them. In order to have a dynamic value be passed to the script it must be visible in the URL. You could, however, use a rewrite rule to add a static GET parameter to a URL that doesn't have one or to convert a visible part of the URL into a GET parameter.
mike333 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 05:32 PM.


Advertisement
Log in to turn off these ads.