homepage Welcome to WebmasterWorld Guest from 54.211.113.223
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
What does this .htaccess mean?
Leah

10+ Year Member



 
Msg#: 4013232 posted 1:04 am on Oct 26, 2009 (gmt 0)

I am working on a clients site & normally when I want to redirect example-A.com to forward to example-B.com I would use the following code:

RewriteEngine on
RewriteRule ^(.*)$ [example-B.com...] [R=301,L]

& then whenever someone types in example-A.com they land on example-B.com.

Beyond blocking bad ip's and the above trick, I really don't know much about .htaccess.

This is the code I found:


RewriteEngine on
# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.originalsite.net
AuthUserFile /home/originalsite/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/originalsite/public_html/_vti_pvt/service.grp

# disable directory browsing
Options All -Indexes

AddType application/x-httpd-php .html .htm .inc
AddHandler application/x-httpd-php .html .htm .incRewriteCond %{HTTP_HOST} ^originalsite.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.originalsite.net$
RewriteRule ^/?$ "http\:\/\/www\.newsitename\.com" [R=301,L]

I did a bit of research & just want to know where I should put my redirect into this configuration.

+ what is going on at the bottom code? It looks like the original webdesigner tried to do a redirect -> which doesn't work. There are currently 2 sites with duplicate content, not a good thing.

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4013232 posted 7:50 am on Oct 26, 2009 (gmt 0)

These lines need to be escaped:

RewriteCond %{HTTP_HOST} ^originalsite[b]\.[/b]net$ [OR]
RewriteCond %{HTTP_HOST} ^www[b]\.[/b]originalsite[b]\.[/b]net$

but I would just do:

RewriteCond %{HTTP_HOST} [b]![/b]^www[b]\.[/b]newsitename[b]\.[/b]net$

There is way too much wrong with this line:

RewriteRule ^/?$ "http\:\/\/www\.newsitename\.com" [R=301,L]

should only be

RewriteRule [i]<pattern>[/i] http[b]://[/b]www[b].[/b]newsitename[b].[/b]com [R=301,L]

The ^/?$ pattern is also odd. It only forwards for root '/' requests, not for any requested folders or sub-pages. Additionally, you need ^$ if the code is in .htaccess and ^/$ if the code is in httpd.conf.

I would use (.*) for <pattern>, and that's one of the rare occasions when using (.*) is the right thing to do (often it is the most inefficient pattern to use).

Leah

10+ Year Member



 
Msg#: 4013232 posted 6:23 pm on Oct 27, 2009 (gmt 0)

Thank you so much for your suggestions. Just a few more nubie questions. Sorry if they are really dumb, I just like to be careful.

1. Is the following correct? I only changed the bottom following your suggestions & the apache.org mod_rewrite pg.

2. I'm still confused on the indexignore. I get that it's saying to look at htaccess first, but what is the rest? & am I correct in seeing the header & readme is commented (if you saw the cpanel dir files you'd be horrified at how sloppy they are, still cleaning house)

Thank you again!

RewriteEngine on
# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.originalsite.net
AuthUserFile /home/originalsite/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/originalsite/public_html/_vti_pvt/service.grp

# disable directory browsing
Options All -Indexes

AddType application/x-httpd-php .html .htm .inc
AddHandler application/x-httpd-php .html .htm .inc

# redirect old site to new site
RewriteRule (.*) [newsitename.com...] [R=301,L]

# always use www version
rewritecond %{http_host} ^newsitename.com [nc]
rewriterule ^(.*)$ [newsitename.com...] [r=301,L]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4013232 posted 7:35 pm on Oct 27, 2009 (gmt 0)

The two redirects are potentially problematic in various ways, depending on whether old-site and new-site are hosted in the same filespace on this same server. In either case, though, it appears that you only need one rule:

# Externally redirect old site to new site (on a different
# server or in a separate filespace on this server)
RewriteRule ^(.*)$ http://www.newsitename.com/$1 [R=301,L]

- or -

# Externally redirect old site to new site (in this same server filespace)
RewriteCond %{HTTP_HOST} !^(www\.newsitename\.com)?$
RewriteRule ^(.*)$ http://www.newsitename.com/$1 [R=301,L]

Note that no allowance is made for incorrect-case requests or for requests using a FQDN or a hostname with a port number appended; This is intentional, since these too should be redirected.

You could also shorten the entire mod_access section to:

Order Deny,Allow
#
<LimitExcept GET POST>
Deny from all
</LimitExcept>

This disallows the use of any HTTP methods other than GET, HEAD, or POST. (HEAD is implied by GET.)

It is neither necessary (nor in most cases desirable) to use "Allow from all" since that will preclude using subsequent Denys to control access by IP address, user-agent, requested URI, etc. See Apache mod_access for details.

Jim

Leah

10+ Year Member



 
Msg#: 4013232 posted 5:02 pm on Oct 28, 2009 (gmt 0)

Thank you for your patience & expertise! You've definitely cleared up a few points I was having trouble with even after reading & re-reading the documentation. :)

L

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved